Recursively list files in Java
问题 How do I recursively list all files under a directory in Java? Does the framework provide any utility? I saw a lot of hacky implementations. But none from the framework or nio 回答1: Java 8 provides a nice stream to process all files in a tree. Files.walk(Paths.get(path)) .filter(Files::isRegularFile) .forEach(System.out::println); This provides a natural way to traverse files. Since it's a stream you can do all nice stream operations on the result such as limit, grouping, mapping, exit early