package elte.java2_utikalauz5.io; import java.io.*; import java.nio.*; import java.nio.channels.*; /** Másolás csatornákkal. @link.forrásfájl {@docRoot}/../data/io/src Masolo2.java @link.letöltés {@docRoot}/../data/io Masolo2.jar @since Java 2 Útikalauz programozóknak 5.0 */ class Masolo2 { public static void másol( ReadableByteChannel in, WritableByteChannel out ) throws IOException { ByteBuffer buffer = ByteBuffer.allocate(1024); while (in.read( (ByteBuffer)buffer.clear() ) != -1) out.write( (ByteBuffer)buffer.flip() ); } public static void main( String[] args ) throws IOException { FileInputStream fin = new FileInputStream(args[0]); try { FileChannel in = fin.getChannel(); FileOutputStream fout = new FileOutputStream(args[1]); try { FileChannel out = fout.getChannel(); másol(in,out); } finally { fout.close(); } } finally { fin.close(); } } }