import java.io.*;
import java.nio.ByteBuffer;
import java.nio.channels.FileChannel;
public class Main {
public static void main(String[] args) throws IOException {
File file = new File("/home/jacy/Downloads/Bliss-v11.9-bullhead-OFFICIAL-20190920.zip");
FileInputStream fileInputStream = new FileInputStream(file);
FileChannel fileChannel = fileInputStream.getChannel();
FileOutputStream fileOutputStream = new FileOutputStream(new File("test.zip"));
FileChannel fileChannelOutput = fileOutputStream.getChannel();
ByteBuffer byteBuffer = ByteBuffer.allocate(4000);
int size = -1;
while ((size = fileChannel.read(byteBuffer)) != -1) {// 这个read也会阻塞
System.out.println(size);
byteBuffer.flip();
fileChannelOutput.write(byteBuffer);
byteBuffer.clear();
}
fileOutputStream.close();
fileInputStream.close();
}
}
java NIO回顾
最新推荐文章于 2024-07-14 15:39:49 发布