Here you can find the source of copyFile(File source, File target)
public static void copyFile(File source, File target) throws IOException
//package com.java2s; import java.io.*; public class Main { public static void copyFile(File source, File target) throws IOException { InputStream in = null;// w w w .j av a2 s. c o m OutputStream out = null; try { in = new BufferedInputStream(new FileInputStream(source)); out = new BufferedOutputStream(new FileOutputStream(target)); int ch; while ((ch = in.read()) != -1) { out.write(ch); } out.flush(); // just in case } finally { if (out != null) try { out.close(); } catch (IOException ioe) { } if (in != null) try { in.close(); } catch (IOException ioe) { } } } }