Java NIO要点
1.通道 (Channel)
2.缓冲区(Buffer)
参考 nio的实现原理
实现
Java用NIO读文件
String path = "G:\\MyDesktop\\Example\\test.txt";
File file = new File(path);
FileInputStream fis = new FileInputStream(file);
// 创建一个通道
FileChannel fc = fis.getChannel();
// 创建缓冲区,分配大小1024
ByteBuffer buffer = ByteBuffer.allocate(1024);
// 从通道读入缓冲区
fc.read(buffer);
buffer