title: How to list a 2 million files directory in java without having an "out of memory" exception
body: <p>I have to deal with a directory of about 2 million xml's to be processed.</p>
  
  <p>I've already solved the processing distributing  the work between machines and threads using queues and everything goes right. </p>
  
  <p>But now the big problem is the bottleneck of reading the directory with the 2 million files in order to fill the queues incrementally.</p>
  
  <p>I've tried using the <code>File.listFiles()</code> method, but it gives me a java <code>out of memory: heap space</code> exception. Any ideas?</p>