對於大文件的讀寫操作

import java.io.*;
import java.nio.*;
import java.nio.channels.*;

public class LargeMappedFiles
 {
  
  static int length = 0x8FFFFFF;
  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.println((char)out.get(i));
   }

 }
 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章