In this section, you will learn how to find the modification date and time of the file.
Description of code:
We have created an instance of File class and specify the file. Then, we have checked whether the specified file exists. It it exists then we have used lastModified() method that will return the modification date and time of the file. This return value is system dependent. The return value is of long type, so in order to display the date and time in a format, we have used SimpleDateFormat class.
exists()- This method File class checks whether the file or directory denoted by the pathname exists or not.
lastModified( )- this method of File class gives the last modification date and time of the specified file or folder name. This method shows the time in millisecond.
SimpleDateFormat- This class is used to formatting and parsing dates in a manner.
format()- This method of SimpleDateFormat class formats a date into a date/time string in a pattern.
Here is the code:
In the above code, we have used lastModified() method of File class to retrieve the last modification data and time of specified file. Through the above code, you can determine the modification date and time of any file or folder.
|Directory modification date and time : 30-08-2010 12:21:52|
Recommend the tutorial