What is the order in which Files.walkFileTree
visits files/directories at the same level?
It doesn't appear to visit them in order of size, last modified time or name. I couldn't find anything in the API documentation either.
Perhaps the preVisitDirectory
method can be used to specify the order of visit but what is default behaviour ?
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 cannot make any assumptions about the iteration order that subdirectories are visited.
As for the order in which the files are read, it depends (in the current implementation) on the supplied DirectoryStream
, which is sun.nio.fs.WindowsDirectoryStream
on my computer. Reading the javadoc of DirectoryStream
, you will see that:
The elements returned by the iterator are in no specific order.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With