This example will demonstrate how to change the file last modified date or late updated timestamp of on a file by using java, guava and apache commons. Lets say you have a change control process that looks at the last modified date when you upload a file. In the event you need to circumvent you can programmatically set the modified date by following the example below which should work on any platform such as linux, windows or macos. We will create a String that will represent the file name through out the snippets below.
Setup
Straight up Java
Java 7 File I/O
Using the java 7 NIO we will set the set the last modified date to 5 days in the past. We will first create a Path which represents the location of the file then using joda we will create a current time. Next we need to create a FileTime object which represents the value of a file's time stamp attribute. Then using the Files utility class we will call the setLastModifiedTime which updates a file's last modified time attribute to the precision supported by the file system.
Google Guava
This example will show setting the last modified to 5 days ago, then calling guava Files.touch which should set the last modified date to current time.
Output
Apache Commons
This example will show setting the last modified to 5 days ago, then calling apache FileUtils.touch which should set the last modified date to current time.