Here you can find the source of copyAFile(File source, File target)
public static void copyAFile(File source, File target) throws IOException
//package com.java2s; //License from project: Open Source License import java.io.File; import java.io.FileInputStream; import java.io.IOException; import java.nio.channels.FileChannel; public class Main { public static void copyAFile(File source, File target) throws IOException { FileInputStream sourceInputStream = null; FileInputStream targetInputStream = null; try {/* w w w. j a va2s. c om*/ sourceInputStream = new FileInputStream(source); targetInputStream = new FileInputStream(target); FileChannel sourceChannel = sourceInputStream.getChannel(); FileChannel targetChannel = targetInputStream.getChannel(); sourceChannel.transferTo(0, sourceChannel.size(), targetChannel); sourceChannel.close(); targetChannel.close(); } finally { if (sourceInputStream != null) { sourceInputStream.close(); } if (targetInputStream != null) { targetInputStream.close(); } } } }