byte[]和InputStream的相互转换
来源:互联网 发布:诺基亚手机解锁软件 编辑:程序博客网 时间:2024/05/31 05:27
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为转换之后的结果
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为转换之后的结果
- import java.io.ByteArrayInputStream;
- import java.io.ByteArrayOutputStream;
- import java.io.IOException;
- import java.io.InputStream;
- public class ByteToInputStream {
- public static final InputStream byte2Input(byte[] buf) {
- return new ByteArrayInputStream(buf);
- }
- public static final byte[] input2byte(InputStream inStream)
- throws IOException {
- ByteArrayOutputStream swapStream = new ByteArrayOutputStream();
- byte[] buff = new byte[100];
- int rc = 0;
- while ((rc = inStream.read(buff, 0, 100)) > 0) {
- swapStream.write(buff, 0, rc);
- }
- byte[] in2b = swapStream.toByteArray();
- return in2b;
- }
- }
0 0
- byte[]和InputStream的相互转换
- byte[]和InputStream的相互转换
- byte[]和InputStream的相互转换
- byte[]和InputStream的相互转换
- byte[]和InputStream的相互转换
- byte[]和InputStream的相互转换
- byte[]和InputStream的相互转换
- byte[]和InputStream的相互转换
- byte[]和InputStream的相互转换
- byte[]和InputStream的相互转换
- byte[]和InputStream的相互转换
- byte[]和InputStream的相互转换
- byte[]和InputStream的相互转换
- inputstream和byte[]相互转换
- byte[]和InputStream的相互转
- 唯爱小粽子:JAVA中String和byte[]和InputStream之间的相互转换
- 【转载】java输入流转为文件 InputStreamToFile 以及 byte[]和InputStream的相互转换
- java.sql.Blob、byte[]、InputStream之间的相互转换
- Android开发笔记(序)写在前面的目录
- PAT-B 1049. 数列的片段和(20)
- angular-directive各个参数介绍
- 面试智力题实例(一)
- 心情杂记
- byte[]和InputStream的相互转换
- 树莓派摄像头监控
- UWP入门(八)--几个简单的控件
- 开启idea自动Build功能
- 关联本地git仓库与Github仓库
- Launcher3源码浅析
- kodi 开源播放器的编译移植
- org.springframework.beans.factory.UnsatisfiedDependencyException异常
- 喷水装置