• 使用通道之间的数据传输(效果,也是实现文件的复制)


    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();
    
        }
    }
    

      

  • 相关阅读:
    hdu 4027 Can you answer these queries?
    Codeforces: Empty Triangle
    hdu 3006 The Number of set
    hdu 3645 Code Management System
    进度条作控件代码
    NORMAL
    callback
    三种形状匹配脚本
    移动点动画
    脚本管理
  • 原文地址:https://www.cnblogs.com/dongyaotou/p/14414205.html
Copyright © 2020-2023  润新知