Here you can find the source of copyFileToStream(File file, OutputStream stream)
Parameter | Description |
---|---|
file | a parameter |
stream | a parameter |
Parameter | Description |
---|
public static void copyFileToStream(File file, OutputStream stream) throws IOException
//package com.java2s; // BSD License (http://www.galagosearch.org/license) import java.io.File; import java.io.FileInputStream; import java.io.IOException; import java.io.OutputStream; public class Main { /**/* w w w .j a v a2 s.c o m*/ * 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). * * @param file * @param stream * @throws java.io.IOException */ public static void copyFileToStream(File file, OutputStream stream) throws IOException { FileInputStream input = new FileInputStream(file); long longLength = file.length(); final int fiveMegabytes = 5 * 1024 * 1024; while (longLength > 0) { int chunk = (int) Math.min(longLength, fiveMegabytes); byte[] data = new byte[chunk]; input.read(data, 0, chunk); stream.write(data, 0, chunk); longLength -= chunk; } input.close(); } }