Java Snippet - Fast File Copy
When using JDK 1.4 and above...
public static void copyFile(File in, File out) {
try {
FileChannel sourceChannel = new FileInputStream(in).getChannel();
FileChannel destinationChannel = new FileOutputStream(out).getChannel();
sourceChannel.transferTo(0, sourceChannel.size(), destinationChannel);
// or, you can also copy it this way
// destinationChannel.transferFrom(sourceChannel, 0, sourceChannel.size());
sourceChannel.close();
destinationChannel.close();
} catch ( Exception e ) {
e.printStackTrace();
}
}
About this entry
You’re currently reading “Java Snippet - Fast File Copy,” an entry on Weblog of Michael Cutler
- Published:
- 17th May 2005 / 10:05pm
- Category:
- Java
No comments
Jump to comment form | comments rss [?] | trackback uri [?]