- 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
Advertisements