English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

كيفية الحصول على وقت آخر تعديل ملف في Java

named in the java.io packageFile represents a file or directory in the system (path name). This class provides various methods to perform various operations on the file/directory.

The class of FilelastModified()The method returns the last modified time of the file/directory represented by the current File object. You can use this method to get the last modified time of a specific file.

Example

Java program to get the last modified time of the directory - Experience Notes

import java.io.File;
import java.util.Date;
public class GettingLastmodifiedTime {
   public static void main(String args[]) {
      String filePath = "D://ExampleDirectory//";
      //Create file object
      File file = new File(filePath);
      //Get last modified time
      long lastModified = file.lastModified();
      Date date = new Date(lastModified);
      System.out.println("Given file was last modified at:");
      System.out.println(date);
   }
}

نتيجة الإخراج

Given file was last modified at:
Wed Jul 03 19:20:50 IST 2019
من المحتمل أن تعجبك