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; // %InstallDIR%\features\org.talend.rcp.branding.%PRODUCTNAME%\%PRODUCTNAME%license.txt import java.io.File; import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; public class Main { public static void copyFile(File source, File target) throws IOException { // Need to recopy the file in one of these cases: // 1. target doesn't exists (never copied) // 2. if the target exists, compare their sizes, once defferent, for the copy. // 2. target exists but source has been modified recently(not used right now) if (!target.exists() || source.length() != target.length() || source.lastModified() > target.lastModified()) { copyFile(new FileInputStream(source), target); }//from w w w . j av a 2s . c o m } public static void copyFile(InputStream source, File target) throws IOException { FileOutputStream fos = null; try { if (!target.getParentFile().exists()) { target.getParentFile().mkdirs(); } fos = new FileOutputStream(target); byte[] buf = new byte[1024]; int i = 0; while ((i = source.read(buf)) != -1) { fos.write(buf, 0, i); } } finally { try { source.close(); } catch (Exception e) { } try { fos.close(); } catch (Exception e) { } } } }