How to discover a File's creation time with Java?

后端 未结 7 1147
遥遥无期
遥遥无期 2020-11-28 10:59

Is there an easy way to discover a File\'s creation time with Java? The File class only has a method to get the \"last modified\" time. According to some resources I found

7条回答
  •  借酒劲吻你
    2020-11-28 11:20

    With the release of Java 7 there is a built-in way to do this:

    Path path = Paths.get("path/to/file");
    BasicFileAttributes attributes = Files.readAttributes(path, BasicFileAttributes.class);
    FileTime creationTime = attributes.creationTime();
    

    It is important to note that not all operating systems provide this information. I believe in those instances this returns the mtime which is the last modified time.

    Windows does provide creation time.

提交回复
热议问题