3
回答
有关于Stream的问题
终于搞明白,存储TCO原来是这样算的>>>   
public static String readStreamToString(InputStream inStream,
String encoding) throws Exception {
ByteArrayOutputStream outStream = new ByteArrayOutputStream();
byte[] buffer = new byte[1024];
int len = 0;
while ((len = inStream.read(buffer)) != -1) {
outStream.write(buffer, 0, len);
}
inStream.close();
return new String(outStream.toByteArray(), encoding);

}

此方法是将InputStream 转成String并存起来,我唯一不理解的是buffer 的长度是1024,大小是1K,当InputStream 很大时,buffer 装不下怎么办?

举报
android_gg
发帖于3年前 3回/100阅
顶部