1. Introduction
The lastModified() method returns the time of the last file modification.
2. Method signature
Parameters:
- method does not take any parameter
Returns
- long - a value representing the time the file was last modified, measured in milliseconds since the epoch (00:00:00 GMT, January 1, 1970), or 0L if the file does not exist or if an I/O error occurs
Throws
- SecurityException - when we do not have access to the file or directory
3. Examples
3.1. Prints the lastModified of a not existing file, a directory and existing file
The output:
4. Conclusion
In this article, we presented a way to check the last modification date using Java IO API. The lastModified method returns time in milliseconds that could be easily converted to the Java 8 Instant
object using Instant.ofEpochMilli
method.
{{ 'Comments (%count%)' | trans {count:count} }}
{{ 'Comments are closed.' | trans }}