Here you can find the source of copyFile(File inputFile, OutputStream os)
Parameter | Description |
---|---|
inputFile | the file to copy |
os | the stream to copy into |
Parameter | Description |
---|---|
IOException | when an error occurs during the copy. |
private static void copyFile(File inputFile, OutputStream os) throws IOException
//package com.java2s; /******************************************************************************* * Copyright 2007(c) G?nome Qu?bec. All rights reserved. * // w w w . j a v a2s . co m * This file is part of GenoByte. * * GenoByte is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 3 * of the License, or (at your option) any later version. * * GenoByte is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. *******************************************************************************/ import java.io.File; import java.io.FileInputStream; import java.io.IOException; import java.io.OutputStream; public class Main { /** * Utility method to copy a file into an {@link java.io.OutputStream}. * * @param inputFile the file to copy * @param os the stream to copy into * @throws IOException when an error occurs during the copy. */ private static void copyFile(File inputFile, OutputStream os) throws IOException { FileInputStream fis = null; try { fis = new FileInputStream(inputFile); // A 1Mb data buffer byte[] buffer = new byte[1024 * 1024]; int n = 0; while ((n = fis.read(buffer)) != -1) { os.write(buffer, 0, n); } } finally { if (fis != null) fis.close(); } } }