Here you can find the source of copyFile(InputStream input, OutputStream output)
private static long copyFile(InputStream input, OutputStream output) throws IOException
//package com.java2s; //License from project: Apache License import java.io.File; import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; public class Main { private static long copyFile(InputStream input, OutputStream output) throws IOException { byte buffer[] = new byte[2048]; long count = 0; int n = 0; while (-1 != (n = input.read(buffer))) { output.write(buffer, 0, n);/* w ww .j a v a2 s .c om*/ count += n; } return count; } private static void write(byte[] from, File file) throws IOException { FileOutputStream fos = new FileOutputStream(file); write(from, fos); } private static void write(byte[] from, OutputStream to) throws IOException { try { to.write(from); } finally { to.close(); } } }