Java Files get last modified time

Description

Java Files get last modified time

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

public class Main {

   public static void main(String[] args) {
      Path path = Paths.get("Main.java");
      FileTime fileTime = FileTime.fromMillis(1000L * 60 * 60 * 24 * 1000);
     //  w ww . ja  v  a 2  s  .  c  om

      try {
         Files.setLastModifiedTime(path, fileTime);
         
         fileTime = Files.getLastModifiedTime(path); 
         System.out.println(fileTime);
      } catch (IOException e) {
         e.printStackTrace();
      } 
      
   }

}



PreviousNext

Related