dcsimg
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX


advertisement
 

Tip: Using the FileTime Class in Java

Learn how to retrieve time-related information regarding files in Java.


advertisement

WEBINAR:

On-Demand

Building the Right Environment to Support AI, Machine Learning and Deep Learning


FileTime is a class in Java that helps you retrieve time-related information regarding files. One such method that we will see below is to get the modified time of a file in FileTime.

Code snippet:

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

public class FileTimeEx
{
   public static void main(String args[]) throws IOException
   {
      FileTimeEx fileTimeEx = new FileTimeEx();
      fileTimeEx.proceed();
   }
   
   private void proceed() throws IOException
   {
      Path filePath = Paths.get("C:/Sridhar/learn/Tips/2019/5-May/FileTimeEx.java");
      FileTime fileTime = Files.getLastModifiedTime(filePath);
      System.out.println("Timestamp of the file: " + fileTime.toString());
   }
}

/*

Expected output:

[root@mypc]# java FileTimeEx
Timestamp of the file: 2019-05-28T07:07:07.773728Z

*/

 

Visit the DevX Tip Bank

 





   
Sridhar M S. is a Java developer from Bangalore, India. He holds a master's degree in Computer Science.
Thanks for your registration, follow us on our social networks to keep up-to-date