Here you can find the source of copyFile(File source, File target)
public static void copyFile(File source, File target)
//package com.java2s; //License from project: Apache License import java.io.*; import java.nio.channels.FileChannel; public class Main { public static void copyFile(File source, File target) { InputStream is = null;/*from w w w. ja v a 2s.c o m*/ try { is = new FileInputStream(source); } catch (FileNotFoundException e) { e.printStackTrace(); } copyFile((FileInputStream) is, target); } public static void copyFile(FileInputStream source, File target) { FileChannel in = null; FileChannel out = null; FileInputStream inStream = null; FileOutputStream outStream = null; try { inStream = source; outStream = new FileOutputStream(target); in = inStream.getChannel(); out = outStream.getChannel(); in.transferTo(0, in.size(), out); } catch (IOException e) { e.printStackTrace(); } finally { close(inStream); close(in); close(outStream); close(out); } } public static void close(Closeable closeable) { try { closeable.close(); } catch (IOException e) { e.printStackTrace(); } } }