I know of the Apache Commons IO library for file directory processing in Java. However, List all files from a directory recursively with Java talks about native support in Java 7.
Does anyone have experience on how to recursively list/read files in a directory using Java 7?
There’s a tutorial on it. Basically you implement a Visitor which can then be called as directories are entered, exited, and files are encountered. There is support for determining if files are symbolic links, and options to follow the symbolic link (if you care to do so). A quick read on what Java
Paths are might be useful, and the entire documentation starts here.A second example (from the Java implementation of
find) that illustrates file walking could be easily modified to “match” all files.On my system (Linux / Fedora), it worked well; however, I was only testing it for functionality, and playing around with it. I didn’t stress test it for performance or any other meaningful measurement (beyond “it works”).