Here you can find the source of readFile(File file, OutputStream output)
public static int readFile(File file, OutputStream output) 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.InputStream; import java.io.OutputStream; public class Main { public static int readFile(File file, OutputStream output) throws IOException { FileInputStream fis = null; try {/*from ww w.ja v a 2 s.c om*/ fis = new FileInputStream(file); return copy(fis, output); } finally { fis.close(); } } public static int copy(InputStream input, OutputStream output) throws IOException { byte[] tempBuff = new byte[1024]; int readCnt; int totalRead = 0; while (true) { readCnt = input.read(tempBuff, 0, tempBuff.length); if (readCnt < 0) { break; } totalRead += readCnt; if (readCnt > 0) { output.write(tempBuff, 0, readCnt); output.flush(); } } return totalRead; } }