Here you can find the source of copyFile(File destFile, File srcFile)
public static void copyFile(File destFile, File srcFile)
//package com.java2s; import java.io.Closeable; import java.io.File; import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.IOException; public class Main { public static void copyFile(File destFile, File srcFile) { if (!srcFile.exists() || null == destFile) { return; }/*from w w w . j a v a 2 s.c o m*/ if (null != destFile.getParentFile()) { destFile.getParentFile().mkdirs(); } FileInputStream fis = null; FileOutputStream fos = null; int buffReaded = 0; try { fis = new FileInputStream(srcFile); fos = new FileOutputStream(destFile); byte[] buff = new byte[1024]; while ((buffReaded = fis.read(buff)) != -1) { fos.write(buff, 0, buffReaded); } } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } finally { close(fis); close(fos); } } public static void close(Closeable c) { if (null != c) { try { c.close(); c = null; } catch (IOException e) { e.printStackTrace(); } } } }