Here you can find the source of copyStream(InputStream fis, OutputStream fos)
public static void copyStream(InputStream fis, OutputStream fos)
//package com.java2s; //License from project: Open Source License import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; public class Main { public static void copyStream(InputStream fis, OutputStream fos) { try {//from w w w. j a v a 2 s . co m byte[] buffer = new byte[0xFFFF]; for (int len; (len = fis.read(buffer)) != -1;) fos.write(buffer, 0, len); } catch (IOException e) { System.err.println(e); } finally { if (fis != null) { try { fis.close(); } catch (IOException e) { e.printStackTrace(); } } if (fos != null) { try { fos.close(); } catch (IOException e) { e.printStackTrace(); } } } } }