title: How to Map files to the Memory in Java nio?
body: <p>I have a text file which I downloaded from the internet. File is large, somewhat around 77MB and I need to map it into the memory so I can read it fast. Here is my code</p>
  
  <pre><code>public class MapRead {
  
      public MapRead()
      {
          try {
              File file = new File("E:/Amazon HashFile/Hash.txt");
              FileChannel c = new RandomAccessFile(file,"r").getChannel();
  
              MappedByteBuffer buffer = c.map(FileChannel.MapMode.READ_ONLY, 0,c.size()).load();
  
              System.out.println(buffer.isLoaded());
              System.out.println(buffer.capacity());
  
          } catch (IOException ex) {
              Logger.getLogger(MapRead.class.getName()).log(Level.SEVERE, null, ex);
          }
      }
  
  
  }
  </code></pre>
  
  <p>No good, this generated the below output.</p>
  
  <pre><code>false
  81022554
  </code></pre>
  
  <p>This is my first time trying this. I have no idea what went wrong, or what to do next, to read the file.</p>