title: Quickest way to read text-file line by line in Java
body: <p>For log processing my application needs to read text files line by line.
  First I used the function readLine() of BufferedReader but I read on the internet that BufferedReader is slow when reading files.<br>
  Afterwards I tried to use FileInputStream together with a FileChannel and MappedByteBuffer but in this case there's no function similar to readLine() so I search my text for a line-break and process it:  </p>
  
  <pre><code>    try {
          FileInputStream f = new FileInputStream(file);
          FileChannel ch = f.getChannel( );
          MappedByteBuffer mb = ch.map(FileChannel.MapMode.READ_ONLY, 0L, ch.size());
          byte[] bytes = new byte[1024];
          int i = 0;
          while (mb.hasRemaining()) {
              byte get = mb.get();
              if(get == '\n') {
                  if(ra.run(new String(bytes)))
                      cnt++;
                  for(int j = 0; j&lt;=i; j++)
                      bytes[j] = 0;
                  i = 0;
              }
              else
                  bytes[i++] = get;
          }
      } catch(Exception ex) {
          ex.printStackTrace();
      }
  </code></pre>
  
  <p>I know this is probably not a good way to implement it but when I just read the text-file in bytes it is 3 times faster then using BufferedReader but calling <code>new String(bytes)</code> creates a new String and makes the program even slower then when using a BufferedReader.<br>
  So I wanted to ask what is the fastest way to read a text-file line by line? Some say BufferedReader is the only solution to this problem.  </p>
  
  <p>P.S.: <code>ra</code> is an instance of RunAutomaton from the dk.brics.Automaton library.</p>