byte[] 和inputStream相互转化
2018-08-28 本文已影响0人
我想起个好名字
1:byte[] -> InputStream
InputStream sbs = new ByteArrayInputStream(byte[] buf);
2:InputStream - > byte[]
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为转换之后的结果