InputStream转ByteArrayOutputStream

来源:互联网 发布:北京网站排名优化 编辑:程序博客网 时间:2024/06/05 08:52

从网络上下载文件获取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);//转换后的输入流}

原创粉丝点击