Here you can find the source of copyFile(String srFile, String dtFile)
public static void copyFile(String srFile, String dtFile) throws IOException
//package com.java2s; //License from project: Open Source License import java.io.File; import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; public class Main { public static void copyFile(String srFile, String dtFile) throws IOException { try {/*from w w w. j a v a2s . c o m*/ File f1 = new File(srFile); File f2 = new File(dtFile); copyFile(f1, f2); } catch (FileNotFoundException ex) { System.out.println(ex.getMessage() + " in the specified directory."); System.exit(0); } catch (IOException e) { System.out.println(e.getMessage()); } } public static void copyFile(File srFile, File dtFile) throws IOException { try { InputStream in = new FileInputStream(srFile); // For Append the file. // OutputStream out = new FileOutputStream(f2,true); // For Overwrite the file. OutputStream out = new FileOutputStream(dtFile); byte[] buf = new byte[1024]; int len; while ((len = in.read(buf)) > 0) { out.write(buf, 0, len); } in.close(); out.close(); System.out.println("File copied."); } catch (FileNotFoundException ex) { System.out.println(ex.getMessage() + " in the specified directory."); System.exit(0); } catch (IOException e) { System.out.println(e.getMessage()); } } }