本帖最后由 黑马_张佳超 于 2012-6-22 17:35 编辑
代码示例:- import java.io.RandomAccessFile;
- import java.nio.MappedByteBuffer;
- import java.nio.channels.FileChannel;
- public class LargeMappedFiles {
- static int length = 0x8FFFFFF;//128MB
- 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; i++)
- System.out.print((char)out.get(i));
- }
- }
复制代码 上边的是原文中示例代码。哪位大虾给分析分析这样操作有何用? |
|