What happens when the entire file isn't in your mapping region? : MappedByteBuffer « File « Java Tutorial






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

public class MainClass {
  private static final int LENGTH = 100; // Small

  public static void main(String[] args) throws Exception {
    MappedByteBuffer in = new FileInputStream("test.txt").getChannel().map(
        FileChannel.MapMode.READ_ONLY, 0, LENGTH);
    int i = 0;
    while (i < LENGTH)
      System.out.print((char) in.get(i++));
    System.out.println((char) in.get(i++));
  }
}








11.49.MappedByteBuffer
11.49.1.Create MappedByteBuffer from FileInputStream
11.49.2.Get MappedByteBuffer from FileChannel
11.49.3.What happens when the entire file isn't in your mapping region?
11.49.4.Create Read only buffer
11.49.5.Locking portions of a mapped file
11.49.6.Creating a very large file using mapping
11.49.7.Read file upside/down with RandomAccessFile
11.49.8.Mapping an entire file into memory for reading