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());
} catch ( Exception e ) {

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top