Quick Tip: How To Update Last Modified Time in Java

There are times that a developer may need to change the last modified time for a file or folder. This Java programming tutorial teaches you how to perform this task. Here a simple code example showing how to modify the last modified property of files and folders in Java:


import java.nio.file.Path;
import java.nio.file.Paths;
import java.nio.file.Files;
import java.nio.file.attribute.FileTime;

public class UpdateLastModifiedTime
	public static void main(String args[])
		UpdateLastModifiedTime updateLastModifiedTime = new UpdateLastModifiedTime();
	private void proceed()
			Path currDir = Paths.get("."); //Current directory
			FileTime now = FileTime.fromMillis(System.currentTimeMillis());
			Files.setLastModifiedTime(currDir, now);
			System.out.println("Updated the last modified time for " + currDir);
		}catch(IOException ioe)
			System.out.println("Exception: " + ioe);


Running this code snippet results in the following output:

[[email protected]]# java UpdateLastModifiedTime
Updated the last modified time for .

Read more Java programming tutorials.


Same AJAX call for multiple button on clicks

Products API using Python Flask, SQL Alchemy and Marshmallow