Here you can find the source of copyFile(File from, File toDir)
public static void copyFile(File from, File toDir) throws IOException
//package com.java2s; //License from project: Open Source License import java.io.*; public class Main { public static void copyFile(File from, File toDir) throws IOException { if (!toDir.isDirectory() || !from.exists()) { throw new IOException("Destination is no Directory or source not exists."); }/* w w w .j av a 2 s . com*/ /* */ copy(from, new File(toDir, from.getName())); } public static void copy(File from, File to) throws IOException { if (!from.exists()) { throw new IOException("Source not exists."); } /* */ InputStream in = null; OutputStream out = null; try { in = new FileInputStream(from); /* create destination file */ out = new FileOutputStream(to); byte[] buf = new byte[1024]; int len; while ((len = in.read(buf)) > 0) { out.write(buf, 0, len); } in.close(); out.close(); } catch (Exception ex) { throw new IOException(ex); } finally { quiteClose(in); quiteClose(out); } } public static String getName(String path) { int index = path.lastIndexOf(File.separatorChar); if (index < 0) { return path; } return path.substring(index + 1); } public static void quiteClose(Closeable stream) { try { if (stream != null) { stream.close(); } } catch (IOException e) { /* Ignore */ } } }