Skip to content

Instantly share code, notes, and snippets.

@varundwarkani
Created May 8, 2020 18:16
Show Gist options
  • Save varundwarkani/b93c83d246413529b8da4e77f4209bbe to your computer and use it in GitHub Desktop.
Save varundwarkani/b93c83d246413529b8da4e77f4209bbe to your computer and use it in GitHub Desktop.
public static void copyFile(FileInputStream fromFile, FileOutputStream toFile) throws IOException {
FileChannel fromChannel = null;
FileChannel toChannel = null;
try {
fromChannel = fromFile.getChannel();
toChannel = toFile.getChannel();
fromChannel.transferTo(0, fromChannel.size(), toChannel);
} finally {
try {
if (fromChannel != null) {
fromChannel.close();
}
} finally {
if (toChannel != null) {
toChannel.close();
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment