Here you can find the source of copyFileToStream(File currentFile, OutputStream outputStream)
private static void copyFileToStream(File currentFile, OutputStream outputStream) throws IOException
//package com.java2s; /******************************************************************************* * Copyright (c) 2011 Sebastian Schmidt and others. All rights reserved. This * program and the accompanying materials are made available under the terms of * the Eclipse Public License v1.0 which accompanies this distribution, and is * available at http://www.eclipse.org/legal/epl-v10.html * // w ww.ja v a 2s .co m * Contributors: Sebastian Schmidt - initial API and implementation ******************************************************************************/ import java.io.File; import java.io.FileInputStream; import java.io.IOException; import java.io.OutputStream; public class Main { private static void copyFileToStream(File currentFile, OutputStream outputStream) throws IOException { int read = 0; byte[] buffer = new byte[8192]; FileInputStream in = new FileInputStream(currentFile); while (-1 != (read = in.read(buffer))) { outputStream.write(buffer, 0, read); } in.close(); } }