FileChannel: transferFrom(ReadableByteChannel src, long position, long count)
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.nio.channels.FileChannel;
public class Main {
public static void main(String[] args) {
FileChannel in = null;
FileChannel out = null;
if (args.length < 2) {
System.out.println("Usage: java Copy <from> <to>");
System.exit(1);
}
try {
in = new FileInputStream(args[0]).getChannel();
out = new FileOutputStream(args[1]).getChannel();
out.transferFrom(in, 0L, (int) in.size());
} catch (Exception e) {
e.printStackTrace();
}
}
}
Related examples in the same category