byte[]和InputStream的相互转换
来源:互联网 发布:淘宝手机详情卖家推荐 编辑:程序博客网 时间:2024/05/20 07:53
: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);
}
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之间的相互转换
- ListView一键返回顶部
- 线程介绍
- 如何用css进行网页布局<mooc>
- 2016.12.03【初中部 NOIP提高C组】模拟赛
- JQuery的文档处理
- byte[]和InputStream的相互转换
- 欧拉函数
- Unity Steam_VR开发工具插件---VRTK 自带案例分析
- Android最佳性能实践(二)分析内存的使用情况
- 设备驱动中的device_driver(kernel-4.7)
- windows:服务启动、暂停、停止按钮不能点击,是灰色如何解决
- 源码方式向openssl中添加新算法完整详细步骤(示例:摘要算法SM3)【非engine方式】
- GreenDao 3.2.0官网介绍的部分翻译(一)
- 腾讯云CentOS7.2 配置PHP7 MySQL 5.7.10