devxlogo

Modifying File Timestamp

Modifying File Timestamp

Question:
Is there any way to change a file’s last modification time from Java?

Answer:
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 tojava.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 callsetLastModified(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.

See also  Why ChatGPT Is So Important Today
devxblackblue

About Our Editorial Process

At DevX, we’re dedicated to tech entrepreneurship. Our team closely follows industry shifts, new products, AI breakthroughs, technology trends, and funding announcements. Articles undergo thorough editing to ensure accuracy and clarity, reflecting DevX’s style and supporting entrepreneurs in the tech sphere.

See our full editorial policy.

About Our Journalist