java8中nio通道(Channel)的基本使用

 时间:2024-10-12 12:43:24

1、利用通道完成文件的复制@Test public void test4() throws Exception{ 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); //inChannel.transferTo(0,inChannel.size(),outChannel); outChannel.transferFrom(inChannel,0,inChannel.size()); inChannel.close(); outChannel.close(); }

java8中nio通道(Channel)的基本使用

3、通道之间的数据传输@Test public void test4() throws Exception{ 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); inChannel.transferTo(0,inChannel.size(),outChannel); }

java8中nio通道(Channel)的基本使用

5、关闭输入通道连接@Test public void test4() throws Exception{ 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); outChannel.transferFrom(inChannel,0,inChannel.size()); inChannel.close(); }

java8中nio通道(Channel)的基本使用
  • 出国去冰岛周边旅游攻略
  • 怎么样精准合理的填报高考志愿
  • 买求婚戒指的价格
  • 《搜神录-魅影灵狐》玩法
  • 导致不孕的原因有哪些
  • 热门搜索
    山东旅游线路 旅游节半价 时尚旅游杂志 北京到黄山旅游攻略 成都华夏旅游商务学校 国庆云南旅游 去朝鲜旅游注意事项 骏途旅游网 名古屋旅游攻略 旅游年票景点