InputStream转byte[]
byte[]转InputStream
private byte[] InputStreamToByte(InputStream is) throws IOException {
ByteArrayOutputStream bytestream = new ByteArrayOutputStream();
int ch;
while ((ch = is.read()) != -1) {
bytestream.write(ch);
}
byte imgdata[] = bytestream.toByteArray();
bytestream.close();
return imgdata;
}
byte[]转InputStream
byte[] data;
InputStream is = new ByteArrayInputStream(data);
本文介绍了如何在Java中实现InputStream到byte[]的转换以及相反的操作。通过提供的代码示例,读者可以了解到具体的实现细节,包括使用ByteArrayOutputStream进行数据读取和转换的方法。
458

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



