本文共 698 字,大约阅读时间需要 2 分钟。
操作系统对内存一次读取的数据大小有要求,但是对于i/O系统,读取大文件是很必要的事情,所以,可以使用内存映射文件系统实现对大文件的读取
代码如下
package com.bird.thinking; import java.io.FileNotFoundException; import java.io.IOException; import java.io.RandomAccessFile; import java.nio.MappedByteBuffer; import java.nio.channels.FileChannel; /** * @use 内存映射文件,对付大文件无法一次性放入到内存中 * @author Bird * */ public class LargeMappedFiles { public static int length = 0x8FFFFFF;//128MB public static void main(String [] args) throws FileNotFoundException, IOException{ MappedByteBuffer out = new RandomAccessFile("d://1.pdf","rw").getChannel().map(FileChannel.MapMode.READ_WRITE, 0, length); for(int i = length/2; i < length/2 + 6; i++){ System.out.println((char)out.get(i)); } } }
转载地址:https://blog.csdn.net/iteye_3606/article/details/82172902 如侵犯您的版权,请留言回复原文章的地址,我们会给您删除此文章,给您带来不便请您谅解!