Convert ByteArrayInputStream to String in Java
Description
The following code shows how to convert ByteArrayInputStream to String.
Example
// w w w. j a v a2s.co m
import java.io.ByteArrayInputStream;
public class Main {
public static String toString(ByteArrayInputStream is) {
int size = is.available();
char[] theChars = new char[size];
byte[] bytes = new byte[size];
is.read(bytes, 0, size);
for (int i = 0; i < size;)
theChars[i] = (char) (bytes[i++] & 0xff);
return new String(theChars);
}
}