title: Best way to read huge file in MB in java
body: <p>I was going through the post and it says either use BufferedReader or MappedByteBuffer. I decided to test on my own with 291.0 MB file but still not able to decide </p>
  
  <pre><code>    BufferedReader reader = new BufferedReader(new FileReader("/Users/rachana/part-00000"));
      String line = null;
      while((line = reader.readLine())!=null) {
          System.out.println(line);
      }
  
  
      ~~~~~~ Heap utilization in MB ~~~~~~
      Start Date  21:10:20
      End Date 21:17:48
      Time used 448 second
             7.50 min
      Used Memory In MB:28
      Free Memory:81
      Total Memory:109
      Max Memory:1820
  </code></pre>
  
  <p>With MappedByteBuffer </p>
  
  <pre><code>RandomAccessFile aFile = new RandomAccessFile
                  ("/Users/rachana/part-00000", "r");
          FileChannel inChannel = aFile.getChannel();
          MappedByteBuffer buffer = inChannel.map(FileChannel.MapMode.READ_ONLY, 0, inChannel.size());
          buffer.load(); 
          for (int i = 0; i &lt; buffer.limit(); i++)
          {
              System.out.print((char) buffer.get());
          }
          buffer.clear(); // do something with the data and clear/compact it.
          inChannel.close();
          aFile.close();
  
  
  
  ~~~~~~ Heap utilization in MB ~~~~~~
   Start Date  21:20:40
   End Date 21:33:52
   Time used 792 sec / 13.2 min
  Used Memory In MB:4 
  Free Memory:104
  Total Memory:109
  Max Memory:1820
  </code></pre>
  
  <p>It clearly states that MappedByteBuffer uses less memory but more time where as BufferedReader uses more memory but less time. </p>
  
  <p>I am trying to find the balance also way to read line using MappedByteBuffer. </p>
  
  <p>Any suggestion will be helpfull</p>