Is there any performance difference between DirectoryStream and File.list()
I have tried to strace both java program in Linux platform, it makes use of getdents64 system call with same parameters. It looks to me both have same performance but different programming paradigm
You might find this interesting:
Mapping java.io.File Functionality to java.nio.file
The performance benefit of DirectoryStream come in the form of memory usage and the ability handle the returned path objects as the directory is being listed rather than building the full list and storing it in memory, then iterating over it. This is beneficial when listing directories containing large numbers of files, or when recursively walking a directory tree.
More info here: http://blog.eyallupu.com/2011/11/java-7-working-with-directories.html
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