The order in which the subdirectories are read is not defined as per this comment in the Java Tutorial: A file tree is walked depth first, but you ...
but you cannot make any assumptions about the iteration order that subdirectories are visited.
One option is to use a Stream: try (Stream
Sridhar : What is the order in which Files.walkFileTree visits files/directories at the same level? It doesn't appear to visit ...
walkFileTree static method from the NIO Files class is used to walk a file tree. The walk traverses the directory tree in a depth-first order.
public static Path walkFileTree(Path start, Set
But the recommendation is, do not build program logic depending on the order of iteration. When doing recursive delete of files and directory, do ...
Here, 'reverseOrder' is used to replace the natural sort order of File objects.
Files.walkFileTree(path, new FileVisitor
Java NIO introduced the walk file tree method that is extremely powerful. It uses the visitor