Created
January 26, 2015 11:51
-
-
Save beyoung/4abd84a525102b7696fa 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
private static void copyFileUsingJava7Files(File source, File dest) | |
throws IOException { | |
Files.copy(source.toPath(), dest.toPath()); | |
} | |
private static void copyFileUsingFileStreams(File source, File dest) | |
throws IOException { | |
InputStream input = null; | |
OutputStream output = null; | |
try { | |
input = new FileInputStream(source); | |
output = new FileOutputStream(dest); | |
byte[] buf = new byte[1024]; | |
int bytesRead; | |
while ((bytesRead = input.read(buf)) > 0) { | |
output.write(buf, 0, bytesRead); | |
} | |
} finally { | |
input.close(); | |
output.close(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment