Here you can find the source of copyFileToStream(File from, OutputStream out)
public static void copyFileToStream(File from, OutputStream out) throws IOException
//package com.java2s; //License from project: Open Source License import java.io.*; public class Main { private static final byte[] BUFFER = new byte[64 * 1024]; public static void copyFileToStream(File from, OutputStream out) throws IOException { InputStream in = new BufferedInputStream(new FileInputStream(from)); try {// w w w. j a v a 2 s. c o m copyStream(in, out); } finally { in.close(); } } public static void copyStream(InputStream in, OutputStream out) throws IOException { while (true) { int read = in.read(BUFFER); if (read < 0) break; out.write(BUFFER, 0, read); } } }