zoukankan      html  css  js  c++  java
  • 使用通道之间的数据传输(效果,也是实现文件的复制)

    package com.nio;
    
    import java.io.IOException;
    import java.nio.channels.FileChannel;
    import java.nio.file.Paths;
    import java.nio.file.StandardOpenOption;
    
    import static java.nio.channels.FileChannel.open;
    
    /**
     * 通道之间的数据传输,这种使用的也是直接缓存区的方式
     */
    public class TestChannel3 {
        public static void main(String[] args) throws IOException {
            //通道之间的数据传输(直接缓存区)
            FileChannel inChannel = FileChannel.open(Paths.get("001.jpg"), StandardOpenOption.READ);
            FileChannel outChannel = FileChannel.open(Paths.get("002.jpg"), StandardOpenOption.WRITE,StandardOpenOption.READ, StandardOpenOption.CREATE);
            //下面的这两种方式效果是一样的 transferTo transferFrom
    //        inChannel.transferTo(0,inChannel.size(),outChannel);
            outChannel.transferFrom(inChannel,0,inChannel.size());
            inChannel.close();
            outChannel.close();
    
        }
    }
    

      

  • 相关阅读:
    Spring boot 梳理
    Spring boot 梳理
    Spring boot 梳理
    观察者模式
    设计模式原则
    Spring MVC上传文件
    Spring MVC视图解析器
    Spring MVC中Action使用总结
    Spring MVC控制器
    Java并发 两个线程交替执行和死锁
  • 原文地址:https://www.cnblogs.com/dongyaotou/p/14414205.html
Copyright © 2011-2022 走看看