title: Fastest way to list files in Java
body: <p>I have tens or even hundreds of thousands of files to list. I thought this would be a rather straightforward thing to do, as for example, running <code>find -iname "*.abc" | wc -l</code> runs instantly on my Ubuntu laptop. Unfortunately, the equivalent code in Java based on the good old File API is quite slow.</p>
  
  <p>The reason seems to be that each <code>File</code> instance contains a lot of metadata, while the <code>find</code> command is smart enough to ignore everything not strictly needed in its search.</p>
  
  <p>It seems that NIO 2 has some "new" constructs to make our lives better: we have a new Visitor based API and a DirectoryStream API. But they still seem to lag somehow in comparison with <code>find</code>.</p>
  
  <p>What is the fastest of the fastest approach in Java when all we need is to list (or, let's say to make it simpler at the moment, count) huge quantities of files in a set of folders?</p>
  
  <p>Thanks</p>