在通道之间复制数据
import java.io.IOException; import java.nio.ByteBuffer; import java.nio.channels.Channels; import java.nio.channels.ReadableByteChannel;/**来 自 n o w j a v a . c o m**/ import java.nio.channels.WritableByteChannel; public class Main { public static void main(String[] argv) throws IOException { ReadableByteChannel source = Channels.newChannel(System.in); WritableByteChannel dest = Channels.newChannel(System.out); channelCopy1(source, dest); source.close(); dest.close(); /** 来自 n o w j a v a . c o m**/ } private static void channelCopy1(ReadableByteChannel src, WritableByteChannel dest) throws IOException { ByteBuffer buffer = ByteBuffer.allocateDirect(16 * 1024); while (src