How to get proper file creation date of file?

后端 未结 3 1912
感动是毒
感动是毒 2021-02-15 16:45

I need not last modification time and not last file accessed time, but file creation time. I have not found information about this. Maybe some libs?

Path p = Pat         


        
3条回答
  •  不思量自难忘°
    2021-02-15 17:29

    How to get the creation date of a file in Java, using BasicFileAttributes class, this is an example:

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

提交回复
热议问题