旅游景点 旅游攻略 日本旅游 文化旅游 旅游景区 昆明旅游 桂林旅游 乡村旅游 上海旅游

java8中nio通道(Channel)的原理与获取

时间:2024-10-16 21:16:36

1、通道:用于源节点与目标节点的连接,在java nio中负责缓冲区中数据的传输。Channel本身不存储数据,因此需要配合缓冲区进行传输。

java8中nio通道(Channel)的原理与获取

3、FileChannel通过open()方法得到通道:FileChannel inChannel = FileChannel.open(Paths.get("1.jpg"), StandardOpenOption.READ); FileChannel outChannel = FileChannel.open(Paths.get("2.jpg"), StandardOpenOption.WRITE, StandardOpenOption.READ,StandardOpenOption.CREATE_NEW);

java8中nio通道(Channel)的原理与获取

5、在JDK1.7中的NIO.2针对各个通道提供了静态方法open()//使用直接缓冲辨泔矣嚣区完成文件的复制(内存映射文件) @Test public void test2() throws Exception{ FileChannel inChannel = FileChannel.open(Paths.get("1.jpg"), StandardOpenOption.READ); FileChannel outChannel = FileChannel.open(Paths.get("2.jpg"),StandardOpenOption.WRITE,StandardOpenOption.CREATE_NEW); }

java8中nio通道(Channel)的原理与获取
© 途途旅游