How to Create a string from a BufferedInputStream using bytes?
This question already has an answer here:
The buffer is too large. Try this:
InputStream content = new FileInputStream(file);
int numRead;
final int bufferSize = 1024;
byte[] buffer = new byte[bufferSize];
ByteArrayOutputStream outString = new ByteArrayOutputStream();
try{
while ((numRead = content.read(buffer)) != -1) {
outString.write(buffer, 0, numRead);
}
} finally {
content.close();
}
return new String(outString.toByteArray());
链接地址: http://www.djcxy.com/p/13734.html