public static void copyFile(File srcFile,File destFile) throws IOException {
  if (destFile.exists() && destFile.isDirectory()) {
    throw new IOException("Destination '" + destFile + "' exists but is a directory");
  }
  FileInputStream input=new FileInputStream(srcFile);
  try {
    FileOutputStream output=new FileOutputStream(destFile);
    try {
      copy(input,output);
    }
  finally {
      close(output);
    }
  }
  finally {
    close(input);
  }
  if (srcFile.length() != destFile.length()) {
    throw new IOException("Failed to copy full contents from '" + srcFile + "' to '"+ destFile+ "'");
  }
  destFile.setLastModified(srcFile.lastModified());
}

public static void copyFile ( File srcFile , File destFile ) throws IOException { if ( destFile . exists ( ) && destFile . isDirectory ( ) ) { throw new IOException ( "Destination '" + destFile + "' exists but is a directory" ) ; } FileInputStream input = new FileInputStream ( srcFile ) ; try { FileOutputStream output = new FileOutputStream ( destFile ) ; try { copy ( input , output ) ; } finally { close ( output ) ; } } finally { close ( input ) ; } if ( srcFile . length ( ) != destFile . length ( ) ) { throw new IOException ( "Failed to copy full contents from '" + srcFile + "' to '" + destFile + "'" ) ; } destFile . setLastModified ( srcFile . lastModified ( ) ) ; }
copy a file preserving the date .
