`
guafei
  • 浏览: 323219 次
  • 性别: Icon_minigender_1
  • 来自: 杭州
社区版块
存档分类
最新评论

读取大文件

阅读更多
package com.IO;

import java.io.RandomAccessFile;
import java.nio.MappedByteBuffer;
import java.nio.channels.FileChannel;

/**
*
* @author guafei.wgf
* java程序读取上G的文件
*
*/

public class LargeMappedFiles {
static int length = 0x8FFFFFF; // 128 Mb

public static void main(String[] args) throws Exception {
MappedByteBuffer out = new RandomAccessFile("test.dat", "rw").getChannel().map(FileChannel.MapMode.READ_WRITE, 0, length);
for (int i = 0; i < length; i++)
out.put((byte) 'x');
System.out.println("Finished   writing ");
for (int i = length / 2; i < length / 2 + 6; i++)
System.out.print((char) out.get(i)); // read file
}
}
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics