Mapping an entire file into memory for reading : MappedByteBuffer « File « Java Tutorial

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

public class MainClass {
  public static void main(String[] args) throws Exception {
    long length = new File("test.txt").length();
    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++));

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