RandomAccessFile: getChannel()

 
import java.io.IOException;
import java.io.RandomAccessFile;
import java.nio.ByteBuffer;
import java.nio.channels.FileChannel;

public class MainClass {
  public static void main(String args[]) {
    RandomAccessFile randomAccessFile;
    FileChannel fileChannel;
    ByteBuffer byteBuffer;

    try {
      randomAccessFile = new RandomAccessFile("test.txt", "rw");
      fileChannel = randomAccessFile.getChannel();
      byteBuffer = fileChannel.map(FileChannel.MapMode.READ_WRITE, 0, 26);
      for (int i = 0; i < 10; i++)
        byteBuffer.put((byte) ('A' + i));
      fileChannel.close();
      randomAccessFile.close();
    } catch (IOException exc) {
      System.out.println(exc);
      System.exit(1);
    }
  }
}
  
Home 
  Java Book 
    File Stream  

RandomAccessFile:
  1. RandomAccessFile
  2. new RandomAccessFile(String fileName, String mode)
  3. RandomAccessFile: close()
  4. RandomAccessFile: getChannel()
  5. RandomAccessFile: getFilePointer()
  6. RandomAccessFile: length()
  7. RandomAccessFile: read(byte[] b)
  8. RandomAccessFile: readBoolean()
  9. RandomAccessFile: readByte()
  10. RandomAccessFile: readChar()
  11. RandomAccessFile: readDouble()
  12. RandomAccessFile: readInt()
  13. RandomAccessFile: readLine()
  14. RandomAccessFile: seek(long pos)
  15. RandomAccessFile: write(byte[] b)
  16. RandomAccessFile: writeBoolean(boolean v)
  17. RandomAccessFile: writeBytes(String s)
  18. RandomAccessFile: writeChars(String s)
  19. RandomAccessFile: writeInt(int v)
  20. RandomAccessFile: writeUTF(String str)