Here you can find the source of copyFile(File src, File dest)
Parameter | Description |
---|---|
src | the source file that will be copied. |
dest | the destination file, result of the copy. |
Parameter | Description |
---|
public static void copyFile(File src, File dest) throws IOException
//package com.java2s; /**//from w w w .j av a 2s . c o m * AADL-RAMSES * * Copyright ? 2014 TELECOM ParisTech and CNRS * * TELECOM ParisTech/LTCI * * Authors: see AUTHORS * * This program is free software: you can redistribute it and/or modify * it under the terms of the Eclipse Public License as published by Eclipse, * either version 1.0 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 * Eclipse Public License for more details. * You should have received a copy of the Eclipse Public License * along with this program. If not, see * http://www.eclipse.org/org/documents/epl-v10.php */ 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 the content of a file (possibly directory) * in another file. Both must be created before calling this * method. * @param src the source file that will be copied. * @param dest the destination file, result of the copy. * @throws for any IO problems */ public static void copyFile(File src, File dest) throws IOException { InputStream in = null; OutputStream out = null; if (dest.isDirectory()) dest = new File(dest, src.getName()); try { in = new FileInputStream(src); out = new FileOutputStream(dest); byte[] buf = new byte[1024]; int len; while ((len = in.read(buf)) > 0) { out.write(buf, 0, len); } } finally { if (in != null) { in.close(); } if (out != null) { out.close(); } } } }