|
Java > IO > Set Last Modified Date |
|
Set Last Modified Date
The following example shows how to set the last modified date of a file.
|
package com.bethecoder.tutorials.io;
import java.io.File;
import java.util.Date;
public class SetLastModifiedTest {
/**
* @param args
*/
public static void main(String[] args) {
File file = new File("C:\\file_ops.txt");
System.out.println(file + " is last modified on " + new Date(file.lastModified()));
file.setLastModified(new Date(150, 1, 1).getTime());
System.out.println(file + " is last modified on " + new Date(file.lastModified()));
}
}
|
| |
It gives the following output,
C:\file_ops.txt is last modified on Thu May 05 11:23:10 IST 2011
C:\file_ops.txt is last modified on Tue Feb 01 00:00:00 IST 2050
|
|