我是靠谱客的博主 魁梧大米,这篇文章主要介绍将InputStream转换为byte数组,现在分享给大家,希望可以做个参考。

感觉不难,但用的时候一时半会写不出来,浪费时间,于是记录下来。

 public static byte[] read(InputStream inputStream) throws IOException {
try {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
byte[] buffer = new byte[1024];
int num = inputStream.read(buffer);
while (num != -1) {
baos.write(buffer, 0, num);
num = inputStream.read(buffer);
}
baos.flush();
return baos.toByteArray();
} finally {
if (inputStream != null) {
inputStream.close();
}
}
}

最后

以上就是魁梧大米最近收集整理的关于将InputStream转换为byte数组的全部内容,更多相关将InputStream转换为byte数组内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(117)

评论列表共有 0 条评论

立即
投稿
返回
顶部