Here you can find the source of copyFile(File destination, File source)
Parameter | Description |
---|---|
destination | Destination file |
source | Source file |
public static void copyFile(File destination, File source) throws java.io.IOException
//package com.java2s; import java.io.File; import java.io.FileInputStream; import java.io.FileOutputStream; public class Main { /**//from w ww. j av a 2 s. co m * Copies the contents of one file to another. * * @param destination * Destination file * @param source * Source file * * @exception java.io.IOException * Thrown if there is an error copying the file. */ public static void copyFile(File destination, File source) throws java.io.IOException { copyFile(destination, source, false); } /** * Copies the contents of one file to another. * * @param destination * Destination file * @param source * Source file * @param deleteSourceFile * whether or not to delete the source file * * @exception java.io.IOException * Thrown if there is an error copying the file. */ public static void copyFile(File destination, File source, boolean deleteSourceFile) throws java.io.IOException { FileInputStream in = null; FileOutputStream out = null; try { in = new FileInputStream(source); out = new FileOutputStream(destination); int len; byte[] buffer = new byte[4096]; while ((len = in.read(buffer)) != -1) { out.write(buffer, 0, len); } } catch (java.io.IOException e) { throw e; } finally { in.close(); out.close(); } if (deleteSourceFile) { source.delete(); } } }