
- Java Programming Examples
- Example - Home
- Example - Environment
- Example - Strings
- Example - Arrays
- Example - Date & Time
- Example - Methods
- Example - Files
- Example - Directories
- Example - Exceptions
- Example - Data Structure
- Example - Collections
- Example - Networking
- Example - Threading
- Example - Applets
- Example - Simple GUI
- Example - JDBC
- Example - Regular Exp
- Example - Apache PDF Box
- Example - Apache POI PPT
- Example - Apache POI Excel
- Example - Apache POI Word
- Example - OpenCV
- Example - Apache Tika
- Example - iText
- Java Tutorial
- Java - Tutorial
- Java Useful Resources
- Java - Quick Guide
- Java - Useful Resources
- 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 print the last modification time of a directory in Java
Problem Description
How to print the last modification time of a directory?
Solution
Following example demonstrates how to get the last modification time of a directory with the help of file.lastModified() method of File class.
import java.io.File; import java.util.Date; public class Main { public static void main(String[] args) { File file = new File("C://FileIO//demo.txt"); System.out.println("last modifed:" + new Date(file.lastModified())); } }
Result
The above code sample will produce the following result.
last modifed:10:20:54
The following is an another sample example of the last modification time of a directory in Java
import java.io.File; import java.io.IOException; import java.io.File; import java.text.SimpleDateFormat; public class Main { public static void main(String[] args) { File f1 = new File("C:\\Users\\TutorialsPoint7\\Desktop\\bbc.txt"); System.out.println("Before Format : " + f1.lastModified()); SimpleDateFormat sdf = new SimpleDateFormat("MM/dd/yyyy HH:mm:ss"); System.out.println("After Format : " + sdf.format(f1.lastModified())); } }
The above code sample will produce the following result.
Before Format : 1479278446484 After Format : 11/16/2016 12:10:46
java_directories.htm
Advertisements