Java Program to Print the Last Modification Time of a Directory
Last modification date of any Folder/Directories having multiple files in it can be displayed using Java. Using last Modified Time method in Java last modification time of any File in any Folder can be extracted.
In a Folder, we have multiple files in it so there will be multiple dates of formation. Then to get the correct modified date for a folder is Difficult because there is a case where a file is created/modified and then deleted from the folder.
So the approach to find the modified date for a folder is by iterating to each file in that folder and calculating the modified time/date for each file whichever time/Date will be small that will be considered as a modified date for a folder
Below is the implementation of the above approach
Modified date/time for a folder:
Here we use the Comparator to the compare the file Modified time with the others file in the same Folder
- Put all files in one array named File.
- Use the comparator to sort all the files in an array-based in the last Modification Date/Time in increasing order.
- Return the first index of the array which will return the modified date/Time for the folder.
Attention reader! Don’t stop learning now. Get hold of all the important Java Foundation and Collections concepts with the Fundamentals of Java and Java Collections Course at a student-friendly price and become industry ready. To complete your preparation from learning a language to DS Algo and many more, please refer Complete Interview Preparation Course.