package cn.bunny.file_dir;

import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.nio.channels.FileChannel;

public class Demo8 {
    public static void main(String[] args) {
        // 只能传输 2g
        try (
                FileChannel fileChannel = new FileInputStream("data.txt").getChannel();
                FileChannel channel = new FileOutputStream("to.txt").getChannel();
        ) {
            // 针对只能传输两个G做了以下优化
            long size = fileChannel.size();
            // 分多次传输两个G内容
            for (long left = size; left > 0; ) {
                left -= fileChannel.transferTo((size - left), left, channel);
            }
            // fileChannel.transferTo(0, fileChannel.size(), channel);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
