/** Java IO, 2nd Edition */ import java.io.*; import java.nio.*; import java.nio.channels.*; public class NIOCopier { public static void main(String[] args) throws IOException { FileInputStream inFile = new FileInputStream(args[0]); FileOutputStream outFile = new FileOutputStream(args[1]); FileChannel inChannel = inFile.getChannel( ); FileChannel outChannel = outFile.getChannel( ); ByteBuffer buffer = ByteBuffer.allocate(1024*1024); while (inChannel.read(buffer) != -1) { buffer.flip( ); while (buffer.hasRemaining( )) outChannel.write(buffer); buffer.clear( ); } inChannel.close( ); outChannel.close( ); } }