byte[]和InputStream的相互转换
来源:互联网 发布:js数组去重复元素 编辑:程序博客网 时间:2024/05/09 00:38
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为转换之后的结果
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之间的相互转换
- 当谈论工程师文化时我们在谈些什么
- 字符串格式转换
- 记负均正
- 2016年3月13日星期日下午
- 多线程 : 线程池的基本用法
- byte[]和InputStream的相互转换
- Android PDF开发:android-pdfview
- Mac配置Apache
- Nginx+PHP服务器运行原理初探
- HDU 1711 KMP
- java 的堆栈问题
- 2014蓝桥杯 第五届 蚂蚁感冒
- 在Windows上基于VS2013搭建IT++库通信系统仿真平台(it++ 4.3.1&&vs2013)
- The 8th Zhejiang Provincial Collegiate Programming Contest->L - Javabeans