Here you can find the source of copyFileToOutputStream(String fileLocation, OutputStream os)
public static void copyFileToOutputStream(String fileLocation, OutputStream os) throws IOException
//package com.java2s; //License from project: Apache License import java.io.*; public class Main { private static final int DEFAULT_BUFFER_SIZE = 1024; public static void copyFileToOutputStream(String fileLocation, OutputStream os) throws IOException { FileInputStream fis = new FileInputStream(fileLocation); copyStream(fis, os);//from w ww. ja v a 2 s. c o m } public static void copyStream(InputStream is, OutputStream os) throws IOException { if (is == null) { throw new IllegalArgumentException("InputStream is null"); } if (os == null) { throw new IllegalArgumentException("OutputStream is null"); } byte[] b = new byte[DEFAULT_BUFFER_SIZE]; int len = 0; try { while ((len = is.read(b, 0, DEFAULT_BUFFER_SIZE)) != -1) { os.write(b, 0, len); } } finally { is.close(); os.flush(); } } }