首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 数据库 > 其他数据库 >

JAVA 性能提拔之 MappedByteBuffer(内存映射)

2012-09-09 
JAVA 性能提升之 MappedByteBuffer(内存映射)import java.io.FileNotFoundExceptionimport java.io.IOExc

JAVA 性能提升之 MappedByteBuffer(内存映射)

import java.io.FileNotFoundException;import java.io.IOException;import java.io.RandomAccessFile;import java.nio.MappedByteBuffer;import java.nio.channels.FileChannel;public class LargeMappedFiles {static int length = 0x8FFFFFF;//128Mpublic static void main(String[] args) {try {MappedByteBuffer out = new RandomAccessFile("test.txt", "rw").getChannel().map(FileChannel.MapMode.READ_WRITE, 0, length);for(int i = 0 ; i < length ; i ++){out.put((byte)i);}System.out.println("Finished writing");for(int i = length/2 ; i < length/2 + 6 ; i ++){System.out.println((char)out.get(i));}} catch (FileNotFoundException e) {e.printStackTrace();} catch (IOException e) {e.printStackTrace();}}}
?

热点排行