Here you can find the source of doCopyFile(File srcFile, File destFile, boolean preserveFileDate)
private static void doCopyFile(File srcFile, File destFile, boolean preserveFileDate) throws IOException
//package com.java2s; //License from project: Apache 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 { private static void doCopyFile(File srcFile, File destFile, boolean preserveFileDate) throws IOException { if ((destFile.exists()) && (destFile.isDirectory())) { throw new IOException("Destination '" + destFile + "' exists but is a directory"); }//from w w w.j ava2 s .co m FileInputStream input = new FileInputStream(srcFile); try { FileOutputStream output = new FileOutputStream(destFile); try { copy(input, output); } finally { closeQuietly(output); } } finally { closeQuietly(input); } if (srcFile.length() != destFile.length()) { throw new IOException("Failed to copy full contents from '" + srcFile + "' to '" + destFile + "'"); } if (preserveFileDate) destFile.setLastModified(srcFile.lastModified()); } public static int copy(InputStream input, OutputStream output) throws IOException { long count = copyLarge(input, output); if (count > 2147483647L) { return -1; } return (int) count; } public static void closeQuietly(InputStream input) { try { if (input != null) input.close(); } catch (IOException ioe) { } } public static void closeQuietly(OutputStream output) { try { if (output != null) output.close(); } catch (IOException ioe) { } } public static long copyLarge(InputStream input, OutputStream output) throws IOException { byte[] buffer = new byte[4096]; long count = 0L; int n = 0; while (-1 != (n = input.read(buffer))) { output.write(buffer, 0, n); count += n; } return count; } }