Here you can find the source of copyFileToStream(File file, OutputStream stream)
Parameter | Description |
---|
public static void copyFileToStream(File file, OutputStream stream) throws IOException
//package com.java2s; // BSD License (http://lemurproject.org/galago-license) import java.io.*; public class Main { /**/*from w ww . ja v a2 s.c om*/ * Copies the data from file into the stream. Note that this method does not * close the stream (in case you want to put more in it). * * @throws java.io.IOException */ public static void copyFileToStream(File file, OutputStream stream) throws IOException { InputStream input = null; try { input = new FileInputStream(file); copyStream(input, stream); } finally { if (input != null) input.close(); } } /** * Copies data from the input stream to the output stream. * * @param input The input stream. * @param output The output stream. * @throws java.io.IOException */ public static void copyStream(InputStream input, OutputStream output) throws IOException { byte[] data = new byte[65536]; while (true) { int bytesRead = input.read(data); if (bytesRead < 0) { break; } output.write(data, 0, bytesRead); } } }