Here you can find the source of copyFile(File source, File destination)
private static void copyFile(File source, File destination) throws FileNotFoundException, IOException
//package com.java2s; import java.io.File; import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.IOException; import java.nio.channels.FileChannel; public class Main { private static void copyFile(File source, File destination) throws FileNotFoundException, IOException { FileChannel inputChannel = null; FileChannel outputChannel = null; try {/*from w ww. j a v a 2 s . com*/ inputChannel = new FileInputStream(source).getChannel(); outputChannel = new FileOutputStream(destination).getChannel(); final long bytesToCopy = inputChannel.size(); final long bytesCopied = inputChannel.transferTo(0, bytesToCopy, outputChannel); if (bytesToCopy != bytesCopied) { throw new IOException("FileChannel.transferTo() failed"); } } finally { if (inputChannel != null) { inputChannel.close(); } if (outputChannel != null) { outputChannel.close(); } } } }