I have a folder containing thousands of files. I plan to read the latest 50 files based on the date created, Java by default reading files created oldest, comparing each file taking lot of time, is there a better way to do this?
I have a Folder \usr\documents\archive have 1000 files in it
want to read 50 documents in the folder based on the file creation.
You can use following to get creation or last modification time
OR
Now since you can take creation time (or last modification time), you can sort files by creation time.
Caution: Iterating each file/directory will take time but it depends on your use case. I would do it if task is running in background but not for operation where user is waiting. I would use cache to periodically process and store result for user facing operations.