ADVERTISEMENT
ADVERTISEMENT

Java program to get the last modification date and time of a file

In this java program, we will learn how to get the file's last modification date and time? Here, we will give a file name and program will print its last modification date and time.
Submitted by IncludeHelp, on October 17, 2017

Given a file name and we have to find its last modification date using java program.

To implement this program, we are using "File" class, and its method "lastModified()" which returns file’s last modification date and time.

Here, we are passing (giving) a file named "IncludeHelp.txt' which is stored in "E:" drive in my system; you can pass any file name with correct path which must be available in your system.

Consider the program

// This program will display date and time 
// of last modification of the file IncludeHelp.txt

import java.io.*;
import java.util.Date;

public class LastModify {
  public static void main(String[] args)

  {
    // Enter the file name here.
    File file = new File("E:/IncludeHelp.txt");

    // lastModified is the predefined function of date class in java.
    long lastModified = file.lastModified();

    // will print when the file last modified.
    System.out.println("File was last modified at : " + new Date(lastModified));
  }
}

Output

File was last modified at : Sun Oct 15 23:23:34 IST 2017

Java File Handling Programs »


ADVERTISEMENT



ADVERTISEMENT



Comments and Discussions


ADVERTISEMENT

ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT

Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates

© https://www.includehelp.com some rights reserved.