package com.itbuluoge.nio;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.nio.ByteBuffer;
import java.nio.channels.FileChannel;
public class GetChannel {
/**
* @param args
* @throws Exception
*/
public static void main(String[] args) throws Exception {
/*文件内容拷贝*/
FileChannel fca=new FileInputStream("data.txt").getChannel();
FileChannel fcb=new FileOutputStream("back.txt").getChannel();
ByteBuffer swap=ByteBuffer.allocate(1000);
fca.read(swap);
while(swap.hasRemaining())
{
swap.flip();
/*写入到新文件*/
fcb.write(swap);
}
}
}
利用filechannel拷贝文件内容
最新推荐文章于 2022-12-04 16:38:27 发布