博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
java nio 快速read大文件
阅读量:6934 次
发布时间:2019-06-27

本文共 544 字,大约阅读时间需要 1 分钟。

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();

 

转载地址:http://rigjl.baihongyu.com/

你可能感兴趣的文章
jsonP格式接口实现
查看>>
INDIGO STUDIO神器!快速创建WEB、移动应用的交互原型工具【转】
查看>>
我的2017云栖之行
查看>>
HSQLDB安装与使用方法
查看>>
重拾C++之初始化
查看>>
maven nexus 下发布第三方构件;
查看>>
Java学习之深拷贝浅拷贝及对象拷贝的两种方式
查看>>
如何根据动态SQL代码自动生成DTO
查看>>
html input="file" 浏览时只显示指定文件类型 xls、xlsx、csv
查看>>
Android Export aborted because fatal error were fo
查看>>
在window平台下模拟Liunx使用GCC环境进行编译C的SO库。
查看>>
原来一直纠结MQ的用法,今天看到了一个最经典的例子。
查看>>
Resource is out of sync with the file system的解决办法
查看>>
交叉编译openssl不修改Makefile的方法
查看>>
linux 常用流量查看命令
查看>>
VMware ESXi Windows虚拟机磁盘扩展小结
查看>>
Linux常用命令
查看>>
方便的将数字转成字符串类型并在前面补0
查看>>
mysql主从复制
查看>>
宫崎骏首次因为自己的新作流泪
查看>>