Here you can find the source of copyFile(File file, OutputStream os)
public static void copyFile(File file, OutputStream os) throws IOException
//package com.java2s; //License from project: Open Source License import java.io.File; import java.io.FileInputStream; import java.io.IOException; import java.io.OutputStream; public class Main { public static void copyFile(File file, OutputStream os) throws IOException { final int buffersize = 4096; FileInputStream fis = new FileInputStream(file); try {/*from w w w . ja v a 2s. com*/ byte[] buf = new byte[buffersize]; int count; while ((count = fis.read(buf, 0, buffersize)) != -1) { os.write(buf, 0, count); } } finally { fis.close(); } } }