Simple and fast recursive find files for Java

This week I needed a simple routine to find files inside a given folder and respective sub folders.

There are plenty of solutions around the web, but these solutions typically use a second method or even more, instead of a single recursive method.

Below is the code that I've written, it is not perfect nor fully tested but it is simple and fast on my Toshiba R630 Win7 laptop (indexed 152450 files in 30Gb of data under 12 seconds), so I'm happy and decided to share this code snippet with the rest of the world.

It will output an array list composed of File objects. You only need to define where (the starting folder) and maxDeep (the level of subfolders that you want to crawl).

If you have suggestions for future improvement, please do mention them and I'll update the snippet along with placing your name on the credits. I liked this solution but I'm by no means a coding guru.

Have fun!



You find the snippet at this doc: http://goo.gl/pKq0D



--- update 1 (23th March 2011), the code was made shorter and simpler. Please update.

--- Benchmarks
Testing on drive D: with 30Gb of data took an average 12 seconds for 152 450 files
Testing on drive C: with 92Gb of data and 476 789 files started with 829 seconds on the initial scan and on posterior scans dropped to an average of 140 seconds.

Machine of these testings was a Toshiba R630, equipped with 4Gb of RAM, an i7 core and Windows 7 x64 bits.

:)