Java FileInputStream Copy copyFileToStream(File currentFile, OutputStream outputStream)

Here you can find the source of copyFileToStream(File currentFile, OutputStream outputStream)

Description

copy File To Stream

License

Open Source License

Declaration

private static void copyFileToStream(File currentFile, OutputStream outputStream) throws IOException 

Method Source Code

//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();
    }
}

Related

  1. CopyFileToDirectory(String file_name, String from_directory, String to_directory)
  2. copyFileToFile(File file, File destFile, boolean overwrite)
  3. copyFileToFile(File input, String outputPath, String exportName)
  4. copyFileToOutputStream(File file, OutputStream stream)
  5. copyFileToOutputStream(String fileLocation, OutputStream os)
  6. copyFileToStream(File file, OutputStream stream)
  7. copyFileToStream(File file, OutputStream stream)
  8. copyFileToString(java.io.File f)
  9. copyFileToZip(final ZipOutputStream zos, final byte[] readBuffer, final File file, final int bytesInOfZip)