I'm listing the files on a file system in Java using the following Apache Commons class:
Collection<File> allFiles = FileUtils.listFiles(rootDirectory, null, recursive);
This is a very long process, and can take up to 5 minutes.
Is there any way I can check the size of the collection while it is being populated?
I tried accessing it from a separate thread but simply got zero until the process was ready.
Until you get a return value from the method, you won't be able to access the collection as it gets populated, because you don't have access to the variable that this method uses internally.
You could split the search in smaller pieces by not using the recursive flag and deal with the recursion yourself to receive a collection per directory.
A better alternative, if you are using Java 7, is to use the FileVisitor
interface to explore the file system. It has a few callback methods that enable you to track the progress.
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