- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to get file last modified time in Java?
He class named File of the java.io package represents a file or directory (path names) in the system. This class provides various methods to perform various operations on files/directories.
The lastModified() method of the File class returns the last modified time of the file/directory represented by the current File object. You can get the last modified time of a particular file using this method.
Example
Following Java program gets the last modified time of a directory −
import java.io.File; import java.util.Date; public class GettingLastmodifiedTime { public static void main(String args[]) { String filePath = "D://ExampleDirectory//"; //Creating the File object File file = new File(filePath); //Getting the last modified time long lastModified = file.lastModified(); Date date = new Date(lastModified); System.out.println("Given file was last modified at: "); System.out.println(date); } }
Output
Given file was last modified at: Wed Jul 03 19:20:50 IST 2019
- Related Articles
- How to check the Date and time of Access (last modified) of a File using Java?
- C# Program to get the last write time of a file
- C# Program to get the last access time of a file
- How to show the date and time the document was last modified with JavaScript?
- How to check file last access time using Python?
- How to display the date and time of a document when it is last modified in JavaScript?
- How to find tables modified in the last hour in Android sqlite?
- How to get file URI reference in Java?
- How to Get File Owner’s Name in Java?
- How to get current Time in Java 8?
- How to get the last dirname/filename in a file path argument in Bash?
- MySQL Query to find tables modified in the last hour?
- How to get first and last elements from ArrayList in Java?
- Get last value in Java TreeSet
- How to find the file modified after a certain date using PowerShell?

Advertisements