我是靠谱客的博主 沉静月光,这篇文章主要介绍byte[]和InputStream的相互转换,现在分享给大家,希望可以做个参考。

1、byte[]转换为InputStream
InputStream sbs = new ByteArrayInputStream(byte[] buf);

2、InputStream转换为InputStreambyte[]
ByteArrayOutputStream swapStream = new ByteArrayOutputStream();
byte[] buff = new byte[100]; //buff用于存放循环读取的临时数据
int rc = 0;
while ((rc = inStream.read(buff, 0, 100)) > 0) {
swapStream.write(buff, 0, rc);
}
byte[] in_b = swapStream.toByteArray(); //in_b为转换之后的结果

最后

以上就是沉静月光最近收集整理的关于byte[]和InputStream的相互转换的全部内容,更多相关byte[]和InputStream内容请搜索靠谱客的其他文章。

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

评论列表共有 0 条评论

立即
投稿
返回
顶部