byte[]和InputStream的相互转换
来源:互联网 发布:阿里云服务器部署 编辑:程序博客网 时间:2024/05/20 07:17
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;
- }
- }
- 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 service 添加
- Uva 375 - Inscribed Circles and Isosceles Triangles
- 面向对象下计算器的编码实现
- 转kidwei 最简单但是却最有用的vtk三维重建代码
- byte[]和InputStream的相互转换
- vc下和gcc的结构体紧凑对齐格式存储【#pragma pack(push,1)、__attribute__ ((packed, aligned(1)))】
- 解开VC++调用.Net DLL的神秘面纱
- visio二次开发---判断文档是否已变化(变化了就加个星号*)
- Java的窗口实例设置小图标
- volatile使用
- perl 取出放回且子集不重复的组合情况
- 学习,不能放
- win7+VS2010跨平台cocos2dx游戏开发环境的搭建