Here you can find the source of copyFile(File source, File destination)
public static void copyFile(File source, File destination)
//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 { public static void copyFile(File source, File destination) { try {//from w w w . j a v a 2 s. co m // From http://java.sun.com/developer/JDCTechTips/2002/tt0507.html. FileInputStream fileInputStream = new FileInputStream(source); FileOutputStream fileOutputStream = new FileOutputStream(destination); FileChannel fileInputChannel = fileInputStream.getChannel(); FileChannel fileOutputChannel = fileOutputStream.getChannel(); fileInputChannel.transferTo(0, fileInputChannel.size(), fileOutputChannel); fileInputChannel.close(); fileOutputChannel.close(); fileInputStream.close(); fileOutputStream.close(); } catch (IOException ex) { throw new RuntimeException("Couldn't copy " + source + " to " + destination + ": " + ex.getMessage()); } } }