0

I want to list out first ten oldest files in a directory. I was looking at JAVA 7 fileVisitor and DirectoryStream interfaces/classes. These API do not visit the files in specific order.Listing out all the files present in the directory and then sorting out them based on creation time and then finding out 10 oldest files seems unoptimized because i have thousands of files present in the directory. Is there any option that i can give to these API so that these apis will visit older files first? Is there any other way to do this in Java or shell ?

vinayakshnd
  • 303
  • 2
  • 8
  • Basically, what you're asking for, can't be done, as the API doesn't provide functionality to pre-sort the file list. Your best choice would be to be build a list of the files and sort it... – MadProgrammer Jul 24 '14 at 05:20
  • there are multiple way to do this. **First:** you can try table database for it Which can store file name and file creation time . now every time you have to just call last ten rows from table. **Second:** Make .property file which contain only oldest file name with their time and make service that update .property file when ever file create,modify and delete. – kamlesh Jul 24 '14 at 05:25

0 Answers0