拷贝InputStream


    public void testIOCopy (CloseableHttpResponse response){ //流只能读取一遍,以下方法可以实现流的复用
        try { HttpEntity entity = response.getEntity(); InputStream in = entity.getContent(); ByteArrayOutputStream out = new ByteArrayOutputStream(); byte[] buffer = new byte[1024]; int len; while ((len = in.read(buffer)) > -1 ) { out.write(buffer, 0, len); } out.flush(); out.close(); in.close(); response.close(); //获取照片流
            byte[] byteArray = out.toByteArray(); InputStream inputStream1 = new ByteArrayInputStream(byteArray); InputStream inputStream2 = new ByteArrayInputStream(byteArray); } catch (Exception e) { // TODO: handle exception
 } }

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM