Here you can find the source of copyFile(InputStream input, OutputStream output)
public static boolean copyFile(InputStream input, OutputStream output)
//package com.java2s; import java.io.File; import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.InputStream; import java.io.OutputStream; public class Main { public static boolean copyFile(File in, File out) { try {/*from w w w.j a va 2 s. co m*/ return copyFile(new FileInputStream(in), new FileOutputStream( out)); } catch (Exception e) { e.printStackTrace(); return false; } } public static boolean copyFile(InputStream in, File out) { try { return copyFile(in, new FileOutputStream(out)); } catch (Exception e) { e.printStackTrace(); return false; } } public static boolean copyFile(InputStream input, OutputStream output) { try { byte[] buf = new byte[1024]; int len; while ((len = input.read(buf)) > 0) { output.write(buf, 0, len); } } catch (Exception e) { e.printStackTrace(); return false; } finally { try { if (input != null) input.close(); if (output != null) output.close(); } catch (Exception e) { } } return true; } }