Skip to content

Instantly share code, notes, and snippets.

@edipofederle
Created April 8, 2013 17:43
Show Gist options
  • Select an option

  • Save edipofederle/5338816 to your computer and use it in GitHub Desktop.

Select an option

Save edipofederle/5338816 to your computer and use it in GitHub Desktop.
public static void copyFile(File sourceFile, File destFile) throws IOException {
if (!sourceFile.exists()) {
return;
}
if (!destFile.exists()) {
destFile.createNewFile();
}
FileChannel source = new FileInputStream(sourceFile).getChannel();
FileChannel destination = new FileOutputStream(destFile).getChannel();
if (destination != null && source != null) {
destination.transferFrom(source, 0, source.size());
}
if (source != null) {
source.close();
}
if (destination != null) {
destination.close();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment