java nio 快速read大文件
If you want to make your first example faster
FileChannel inChannel = new FileInputStream(fileName).getChannel(); ByteBuffer buffer = ByteBuffer.allocateDirect(CAPACITY); while(inChannel.read(buffer) > 0) buffer.clear(); // do something with the data and clear/compact it. inChannel.close();
If you want it to be even faster.
FileChannel inChannel = new RandomAccessFile(fileName, "r").getChannel(); MappedByteBuffer buffer = inChannel.map(FileChannel.MapMode.READ_ONLY, 0, inChannel.size()); // access the buffer as you wish. inChannel.close();
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
支付宝扫一扫捐赠
支付宝扫一扫捐赠
![支付宝扫一扫捐赠](https://images.cnblogs.com/cnblogs_com/welhzh/2159800/o_220512091701_hzh_alipay.jpg)
微信公众号: 共鸣圈
欢迎讨论,邮件: 924948$qq.com 请把$改成@
QQ群:263132197
QQ: 924948