Browse DevX
Sign up for e-mail newsletters from DevX

Tip of the Day
Language: Java
Expertise: Beginner
Apr 5, 1999



Building the Right Environment to Support AI, Machine Learning and Deep Learning

Modifying File Timestamp

Is there any way to change a file's last modification time from Java?

It is not possible to alter the time of last modification in Java version before the 1.2 JDK. One of the new features introduced to java.io.File in the Java 2 Platform is the ability to reset the last modified time. Your question is an example of a situation that Java programmers face constantly. With each new Java release, many major features are introduced, but many minor changes also creep in, making it difficult to stay on top of all of the APIs.

Back to your question: all you have to do is call setLastModified(long time). The time argument should be a time measured in milliseconds since midnight GMT, January 1, 1970. The method will return true if it can set the time, false if it cannot.

DevX Pro
Comment and Contribute






(Maximum characters: 1200). You have 1200 characters left.



Thanks for your registration, follow us on our social networks to keep up-to-date