读取InputSteam中的内容
public static byte[] read(InputStream is) throws Exception {
ByteArrayOutputStream os = new ByteArrayOutputStream();
byte[] buffer = new byte[1024];
int len = 0;
while ((len = is.read(buffer)) != -1) {
os.write(buffer, 0, len);
}
is.close();
return os.toByteArray();
}

本文介绍了一种从InputStream中读取内容的方法,并通过ByteArrayOutputStream将读取的数据转换为byte数组返回。该方法使用了1024字节大小的缓冲区进行高效读取。
4266

被折叠的 条评论
为什么被折叠?



