Here you can find the source of copyFile(File src, File dest, int bufSize)
Parameter | Description |
---|---|
src | the source file that should be copied |
dest | the destination filename and path |
bufSize | the buffer size |
Parameter | Description |
---|---|
IOException | an exception |
public static void copyFile(File src, File dest, int bufSize) throws IOException
//package com.java2s; /*//from ww w .j a v a 2 s .co m * Zettelkasten - nach Luhmann ** Copyright (C) 2001-2014 by Daniel L?decke (http://www.danielluedecke.de) * * Homepage: http://zettelkasten.danielluedecke.de * * * 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 3 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, see <http://www.gnu.org/licenses/>. * * * Dieses Programm ist freie Software. Sie k?nnen es unter den Bedingungen der GNU * General Public License, wie von der Free Software Foundation ver?ffentlicht, weitergeben * und/oder modifizieren, entweder gem?? Version 3 der Lizenz oder (wenn Sie m?chten) * jeder sp?teren Version. * * Die Ver?ffentlichung dieses Programms erfolgt in der Hoffnung, da? es Ihnen von Nutzen sein * wird, aber OHNE IRGENDEINE GARANTIE, sogar ohne die implizite Garantie der MARKTREIFE oder * der VERWENDBARKEIT F?R EINEN BESTIMMTEN ZWECK. Details finden Sie in der * GNU General Public License. * * Sie sollten ein Exemplar der GNU General Public License zusammen mit diesem Programm * erhalten haben. Falls nicht, siehe <http://www.gnu.org/licenses/>. */ import java.io.File; import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; public class Main { /** * This method copies a file. check for existing files is not done here, needs to be * checked from within the method which calls this method. * * @param src the source file that should be copied * @param dest the destination filename and path * @param bufSize the buffer size * @throws IOException */ public static void copyFile(File src, File dest, int bufSize) throws IOException { byte[] buffer = new byte[bufSize]; InputStream in = null; OutputStream out = null; try { in = new FileInputStream(src); out = new FileOutputStream(dest); while (true) { int read = in.read(buffer); if (read == -1) { break; } out.write(buffer, 0, read); } } finally { if (in != null) { try { in.close(); } finally { if (out != null) { out.close(); } } } } } }