Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Performance difference between DirectoryStream and File.list() in travesing folder

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

like image 547
Mike Lee Avatar asked Feb 19 '26 05:02

Mike Lee


2 Answers

You might find this interesting:

Mapping java.io.File Functionality to java.nio.file

like image 96
fstamour Avatar answered Feb 20 '26 18:02

fstamour


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

like image 36
IgnisFatuus Avatar answered Feb 20 '26 17:02

IgnisFatuus



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!