Apps/Gaming

Quick Tip: How to Update the Last Modified Time in Java

There are times when a developer needs to change the last modified time for a file or folder. This Java programming tutorial will show you how to complete this task. Here is a simple code example showing how to change the most recently changed 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; import java.io. *; public class UpdateLastModifiedTime {public static void main (String args[]) {UpdateLastModifiedTime updateLastModifiedTime = new UpdateLastModifiedTime (); updateLastModifiedTime.proceed (); } private void continue () {try {path currDir = Paths.get (“.”); // Current directory FileTime now = FileTime.fromMillis (System.currentTimeMillis ()); Files.setLastModifiedTime (currDir, now); System.out.println (“The last modification time was updated for” + currDir); } catch (IOException ioe) {System.out.println (“Exception:” + ioe); }}} / *

Running this snippet of code results in the following output:

[[email protected]]# java UpdateLastModifiedTime Updates the last modification time for.

Read more tutorials on Java programming.

Related posts

Introduction to Business Process Management and Workflow

TechLifely

CAPM Certification Training for Project Managers

TechLifely

Project Place Project Management Review

TechLifely

Leave a Comment