Here you can find the source of copyFile(File source, File destination)
Parameter | Description |
---|---|
source | the name of the source file |
destination | the name of the destination file |
Parameter | Description |
---|---|
IOException | an exception |
public static void copyFile(File source, File destination) throws IOException
//package com.java2s; //License from project: Open Source License import java.io.File; import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.IOException; import java.nio.channels.FileChannel; public class Main { /**//from w w w .j a v a 2 s . c om * Copies a file. * * @param source * the name of the source file * @param destination * the name of the destination file * @throws IOException */ public static void copyFile(File source, File destination) throws IOException { FileChannel srcChannel = new FileInputStream(source).getChannel(); FileChannel dstChannel = new FileOutputStream(destination).getChannel(); dstChannel.transferFrom(srcChannel, 0, srcChannel.size()); srcChannel.close(); dstChannel.close(); } public static void copyFile(String source, String destination) throws IOException { copyFile(new File(source), new File(destination)); } }