从网络上下载文件获取InputStream流中断查看:http://blog.csdn.net/hjgzj/article/details/78658150
InputStream转ByteArrayOutputStream主要用来解决从网络上获取InputStream中断的问题。
public static void main(String[] args) throws IOException {
InputStream inputStream = new FileInputStream(new File("c:\\logo.jpg"));//原始输入流
ByteArrayOutputStream baos = new ByteArrayOutputStream();
byte[] buffer = new byte[1024];
int len;
byte[] dataBytes;
while ((len = inputStream.read(buffer)) != -1 ) {
baos.write(buffer, 0, len);
}
baos.flush();
dataBytes = baos.toByteArray();
InputStream is = new ByteArrayInputStream(dataBytes);//转换后的输入流
}