Java tutorial
//package com.java2s; import java.io.File; import java.io.FileOutputStream; public class Main { public static void copyFile(File fromFile, File toFile, Boolean rewrite) { if (!fromFile.exists()) { return; } if (!fromFile.isFile()) { return; } if (!fromFile.canRead()) { return; } if (!toFile.getParentFile().exists()) { toFile.getParentFile().mkdirs(); } if (toFile.exists() && rewrite) { toFile.delete(); } try { java.io.FileInputStream fosfrom = new java.io.FileInputStream(fromFile); java.io.FileOutputStream fosto = new FileOutputStream(toFile); byte bt[] = new byte[1024]; int c; while ((c = fosfrom.read(bt)) > 0) { fosto.write(bt, 0, c); } fosfrom.close(); fosto.close(); } catch (Exception ex) { ex.printStackTrace(); } } }