/**
* 通过InputStream 转Byte数组
*
* @param inStream
* @return
* @throws IOException
*/
public static final byte[] inputToByte(InputStream inStream) throws IOException {
ByteArrayOutputStream swapStream = new ByteArrayOutputStream();
byte[] buff = new byte[PmsConstantsFinal.INPUTSTREAM_TO_BYTE];
int rc = 0;
while ((rc = inStream.read(buff, 0, PmsConstantsFinal.INPUTSTREAM_TO_BYTE)) > 0) {
swapStream.write(buff, 0, rc);
}
byte[] in2b = swapStream.toByteArray();
return in2b;
}
转载于:https://www.cnblogs.com/chen-zhi/p/10194723.html
本文介绍了一种将InputStream转换为Byte数组的有效方法。通过使用ByteArrayOutputStream和缓冲区,该方法可以读取输入流并将其转换为字节数组,适用于各种文件读取场景。
6765

被折叠的 条评论
为什么被折叠?



