Here you can find the source of copy(File sourceFile, File targetFile)
public static void copy(File sourceFile, File targetFile) throws IOException
//package com.java2s; //License from project: LGPL import java.io.*; import java.nio.channels.FileChannel; public class Main { public static void copy(File sourceFile, File targetFile) throws IOException { FileChannel sourceChannel = null; FileChannel targetChannel = null; try {/*from w w w . j a va2 s. com*/ sourceChannel = new FileInputStream(sourceFile).getChannel(); targetChannel = new FileOutputStream(targetFile).getChannel(); targetChannel.transferFrom(sourceChannel, 0, sourceChannel.size()); } finally { if (sourceChannel != null) closeQuietly(sourceChannel); if (targetChannel != null) closeQuietly(targetChannel); } } public static void closeQuietly(Closeable closeable) { try { closeable.close(); } catch (IOException ignore) { // } } }