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

后端 未结 7 1132
遥遥无期
遥遥无期 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:01

    This is a basic example in Java, using BasicFileAttributes class:

       Path path = Paths.get("C:\\Users\\jorgesys\\workspaceJava\\myfile.txt");
        BasicFileAttributes attr;
        try {
          attr = Files.readAttributes(path, BasicFileAttributes.class);
          System.out.println("File creation time: " + attr.creationTime());
        } catch (IOException e) {
          System.out.println("oops un error! " + e.getMessage());
        }
    

提交回复
热议问题