Here you can find the source of copyFile(File from, File to)
public static void copyFile(File from, File to) throws IOException
//package com.java2s; //License from project: Open Source License import java.io.*; import java.nio.channels.FileChannel; public class Main { public static void copyFile(File from, File to) throws IOException { if (!from.exists()) { throw new FileNotFoundException(); }//w ww . j a v a 2 s. c o m if (from.isDirectory() || to.isDirectory()) { throw new FileNotFoundException(); } FileInputStream fi = null; FileChannel in = null; FileOutputStream fo = null; FileChannel out = null; try { if (!to.exists()) { to.createNewFile(); } fi = new FileInputStream(from); in = fi.getChannel(); fo = new FileOutputStream(to); out = fo.getChannel(); in.transferTo(0, in.size(), out); } finally { if (fi != null) fi.close(); if (in != null) in.close(); if (fo != null) fo.close(); if (out != null) out.close(); } } }