Here you can find the source of copyFile(File source, File dest)
public static void copyFile(File source, File dest)
//package com.java2s; //License from project: Apache License import java.io.File; import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; import java.nio.channels.FileChannel; public class Main { public static void copyFile(File source, File dest) { FileChannel inputChannel = null; FileChannel outputChannel = null; try {/* ww w. j a va 2 s. com*/ try { inputChannel = new FileInputStream(source).getChannel(); outputChannel = new FileOutputStream(dest).getChannel(); outputChannel.transferFrom(inputChannel, 0, inputChannel.size()); } finally { if (inputChannel != null) { inputChannel.close(); } if (outputChannel != null) { outputChannel.close(); } } } catch (Exception e) { e.printStackTrace(); } } /** * Closes InputStream and/or OutputStream. It makes sure that both streams * tried to be closed, even first throws an exception. * * @throw IOException if stream (is not null and) cannot be closed. * */ protected static void close(InputStream iStream, OutputStream oStream) throws IOException { try { if (iStream != null) { iStream.close(); } } finally { if (oStream != null) { oStream.close(); } } } }