import java.io.*;
import java.nio.*;
import java.nio.channels.*;
public class ChannelCopy {
public static void main(String[] args) throws IOException {
if (args.length!=2) {
System.err.println("Usage: java ChannelCopy <from> <to>");
System.exit(1);
}
FileInputStream in = new FileInputStream(args[0]);
ReadableByteChannel cin = Channels.newChannel(in);
FileOutputStream out = new FileOutputStream(args[1]);
WritableByteChannel cout = Channels.newChannel(out);
ByteBuffer byteB = ByteBuffer.allocate(1000);
int nb;
try {
while ((nb=cin.read(byteB))!=-1) {
byteB.flip(); cout.write(byteB);
byteB.clear(); }
} finally {
cin.close(); cout.close();
}
}
}