How to get the most recent file of a directory in Java

Viewed 6369

Let's say that I have a specific directory on a system (specifically Ubuntu) with say backups or logs generated by other programs. How would I locate and open the most recently created (or modified) file as a File in Java?

I will need a solution that does not rely on a scenario where filenames are named after a timestamp or sequential names like log1,log2, etc.... Subdirectories will be ignored.

2 Answers
Related