Read file upside/down with RandomAccessFile : MappedByteBuffer « File « Java Tutorial

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

public class Main {
  public static void main(String[] args) throws Exception {
    RandomAccessFile f = new RandomAccessFile("hello.txt", "rw");
    FileChannel fc = f.getChannel();
    MappedByteBuffer mbb =, 0, f.length());

    int len = (int) f.length();
    for (int i = 0, j = len - 1; i < j; i++, j--) {
      byte b = mbb.get(i);
      mbb.put(i, mbb.get(j));
      mbb.put(j, b);

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