Java source code examples

Java source code samples. Java code examples.

Change the last modified date of a file or directory.

2 votes Vote!!

Change the last modified date of a file or directory.

The setLastModified method of file class can be used for changing the last modified time of a directory or a file.

import java.io.File;
import java.util.Date;
/**
 * File class examples
 */
public class FileExample  {
	public static void main(String[] args){
		// Create file object representing the source file/directory
		File file = new File("d:\\temp\\test.txt");

		// Get the current time
		long time = new Date().getTime();

		// Change the last modified time.
		file.setLastModified(time);
	}
}
  • Share/Bookmark

Tags: java.io

Discuss This Code