Here you can find the source of copyStream(InputStream sourceInputStream, OutputStream targetOutputStream)
static public void copyStream(InputStream sourceInputStream, OutputStream targetOutputStream) throws Exception
//package com.java2s; //License from project: Open Source License import java.io.InputStream; import java.io.OutputStream; public class Main { static public void copyStream(InputStream sourceInputStream, OutputStream targetOutputStream) throws Exception { int length = 1024; byte[] bytes = new byte[length]; int c;/*www .j a v a 2s. c o m*/ int total_bytes = 0; try { while ((c = sourceInputStream.read(bytes)) != -1) { total_bytes += c; targetOutputStream.write(bytes, 0, c); } } finally { if (sourceInputStream != null) try { sourceInputStream.close(); } catch (Exception e) { } if (targetOutputStream != null) try { targetOutputStream.close(); } catch (Exception e) { } } } }