Skip to content

Instantly share code, notes, and snippets.

@beyoung
Created January 26, 2015 11:51
Show Gist options
  • Save beyoung/4abd84a525102b7696fa to your computer and use it in GitHub Desktop.
Save beyoung/4abd84a525102b7696fa to your computer and use it in GitHub Desktop.
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