package utils;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.nio.ByteBuffer;
import java.nio.channels.FileChannel;
public class ReadLargeTextWithNIO
{
public static void main(String...args) throws IOException
{
String filename="Visual.zip";
FileInputStream fin = new FileInputStream("c:\\2011-01-18\\"+filename);
FileChannel fcin = fin.getChannel();
ByteBuffer buffer = ByteBuffer.allocate(1024 * 1024 * 20);
int n=0;
while(true)
{
buffer.clear();
int flag = fcin.read(buffer);
if(flag == -1)
{
break;
}
buffer.flip();
n++;
FileOutputStream fout = new FileOutputStream("c:\\2011-01-18\\"+filename+"."+n + ".bak");
FileChannel fcout = fout.getChannel();
fcout.write(buffer);
}
}
}
nio分割普通文件
最新推荐文章于 2025-07-09 11:12:14 发布
