Possible Duplicate:
How do I find the last modified file in a directory in Java?
I have a directory of files that I need to check for changes. I consider it changed when one of the files has a modifiedDate
newer than what I remembered from the last check (this is meant to be a cache dependency).
What would be the fastest way of finding the latest modified file in a directory in Java?
Maybe I'm too optimistic, but I'm explicitly looking for something that does not involve iterating all the files.
Also, checking the directory modified date is not enough, as this only changes when the list of files inside changes, not when one of the files themselves is just modified.
Even if you're not looking to iterate all of the files, any third-party API you use to find this will iterate all of the files.
JDK 7 is intended to have java.nio.WatchService, which will apparently iterate through everything if it has to, but will use filesystem support to do exactly what you've asked for. On the minus side, that's still in the future.
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