Home  >  Article  >  Java  >  Java Example - Get file modification time

Java Example - Get file modification time

黄舟
黄舟Original
2017-02-15 10:29:191336browse

The following example demonstrates using the file.lastModified() method of the File class to obtain the last modification time of the file

/*
 author by w3cschool.cc
 Main.java
 */import java.io.File;import java.util.Date;public class Main {
   public static void main(String[] args) {
      File file = new File("Main.java");
      Long lastModified = file.lastModified();
      Date date = new Date(lastModified);
      System.out.println(date);
   }}

The output result of running the above code is:

Thu Apr 09 09:40:19 CST 2015

The above is the Java example - getting the content of the file modification time. For more related content, please pay attention to the PHP Chinese website (www.php.cn)!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn