Here you can find the source of copyFile(InputStream is, OutputStream os)
Parameter | Description |
---|---|
is | a parameter |
os | a parameter |
Parameter | Description |
---|
public static void copyFile(InputStream is, OutputStream os) throws IOException
//package com.java2s; /*/*from w ww .ja v a 2 s. co m*/ Copyright (C) 2007 Joao F. (joaof@sourceforge.net) http://paccman.sourceforge.net This program 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 2 of the License, or (at your option) any later version. This program 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, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ import java.io.File; import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; import java.nio.channels.FileChannel; public class Main { private static final int BUF_SIZE = 256 * 1024; /** * * @param is * @param os * @throws java.io.IOException */ public static void copyFile(InputStream is, OutputStream os) throws IOException { byte[] buf = new byte[BUF_SIZE]; int len; while ((len = is.read(buf)) > 0) { os.write(buf, 0, len); } is.close(); os.close(); } /** * Copy <code>inputFile</code> to <code>outputFile</code> * @param inputFile The source file. * @param outputFile The destination file. * @throws java.io.IOException */ public static void copyFile(File inputFile, File outputFile) throws IOException { // Create channel on the source FileChannel srcChannel = new FileInputStream(inputFile).getChannel(); // Create channel on the destination FileChannel dstChannel = new FileOutputStream(outputFile).getChannel(); // Copy file contents from source to destination dstChannel.transferFrom(srcChannel, 0, srcChannel.size()); // Close the channels srcChannel.close(); dstChannel.close(); } }