Using the methods StringBuilderand read(char[], int, int)will look like, and probably this is the best way to do this in Java:
final MAX_BUFFER_SIZE = 256;
StringBuilder result = new StringBuilder();
char[] buffer = new char[MAX_BUFFER_SIZE];
int readChars;
while ((readChars = stream.read(buffer, 0, MAX_BUFFER_SIZE)) > 0) {
result.append(buffer, 0, readChars);
}
return result.toString();
source
share