title: FileChannel vs MappedByteBuffer in random access?
body: <p>As far as I know, MappedByteBuffer has several benefits, such as:</p>
  
  <ol>
  <li><p>It map the user space memory address to the kernel space memory address, so that it avoids memory copy from kernel space to user space while reading from file</p></li>
  <li><p>After the first read of a piece in the file (etc an offset from 0 to 100 in the buffer), this piece would be cached in the memory, so when the second time you read the same piece from the buffer, you are reading it from the memory directly but not from the disk.</p></li>
  </ol>
  
  <p>My question is:</p>
  
  <ol>
  <li><p>Is my understanding above is correct?</p></li>
  <li><p>If my understanding is correct, when you read the piece just once (never read it again so it would not read it from the memory), is it the same by using FileChannel.read(buffer, position) and using MappedByteBuffer.get(byte[], offset, length)?</p></li>
  <li><p>For the random accessing to a file (not read the same piece repeatedly), is FileChannel would be more efficient because MappedByteBuffer would take the memory it map while FileChannel need no memory?</p></li>
  <li><p>What's difference between I use a MappedByteBuffer and I simply load the whole file into my memory. The benefit of MappedByteBuffer is that it use a memory outside the JVM heap so no GC concern?     </p></li>
  </ol>