package com.hao.demo.netty.nio;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.nio.channels.FileChannel;
/**
* @author haoxiansheng
* @date 2020-05-11
*/
public class NIOFileChannel04 {
public static void main(String[] args) throws Exception{
// 创建流
FileInputStream fileInputStream = new FileInputStream("path1");
FileOutputStream fileOutputStream = new FileOutputStream("path2");
// 获取 channel
FileChannel source = fileInputStream.getChannel();
FileChannel target = fileOutputStream.getChannel();
// 使用transferFrom 完成拷贝
target.transferFrom(source, 0, source.size());
// 关闭流
source.close();
target.close();
fileInputStream.close();
fileOutputStream.close();
}
}