title: Why is FileInputStream so slow?
body: <p>I'm using <code>RHEL7</code>.</p>
  
  <p>I'm working on an application which is supposed to load large amount of data from the outside. I have <code>ramdisk</code> which is stored inside the <code>RAM</code> and is supposed to be read very fast. I access it in two ways:</p>
  
  <ol>
  <li><p><code>FileInputStream</code></p>
  
  <pre><code>public static void main(String [] args){
      try(InputStream fis = new FileInputStream(new File("/mnt/ramdisk/file"))
           BufferedReader r = new BufferedReader(new InputStreamReader(fis))){
  
           while(//till the end of stream
                 ){
               byte[] buffer = new byte[_some_size_];
               r.read(buffer);
               //Do something useful
           }
  }
  </code></pre></li>
  <li><p>Read through <code>System.in</code>. <code>cat ramdisk/file | java -cp my.jar com.test.Main</code></p>
  
  <pre><code>The same as 1, but the stream is System.in.
  </code></pre></li>
  </ol>
  
  <p>The second way is much faster. On my machine in works about 7 times faster than the first one.</p>
  
  <p>Can someone explain the performance difference? I would like to understand it. </p>