Created
May 8, 2020 18:16
-
-
Save varundwarkani/b93c83d246413529b8da4e77f4209bbe to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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