Java Codes
Beginners
Core Java
Date Time
Java2D
Java Applets
Java AWT
Mathematics
Networking
Servlets
Session
Sound
Swing
Threads
Util Package
JDBC
Learning
Other
Security
XML
Java > Core Java sample source codes
Getting and Setting the Modification Time of a File or Directory
Getting and Setting the Modification Time of a File or Directory public static void main(String args[]){ try{ File file = new File("file.txt"); // Get the last modified time long modifiedTime = file.lastModified(); // 0L is returned if the file does not exist // Set the last modified time long newModifiedTime = System.currentTimeMillis(); boolean success = file.setLastModified(newModifiedTime); if (!success) { System.out.println("Operation failed"); } } catch (Exception ioe){ ioe.printStackTrace(); } }
Privacy Policy
|
Link to Us
|
Links