Here you can find the source of copyfile(File srFile, File dtFile)
public static void copyfile(File srFile, File dtFile) throws IOException
//package com.java2s; //License from project: Open Source License import java.io.File; import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; public class Main { public static void copyfile(File srFile, File dtFile) throws IOException { InputStream in = new FileInputStream(srFile); File desDir = dtFile.getParentFile(); if (!desDir.exists()) { boolean ret = desDir.mkdirs(); if (!ret) throw new IOException("Cannot create directory " + desDir.getName()); }/*from ww w . ja va 2 s . c o m*/ // 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(); } }