Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Creation date of file  RSS feed

 
Z Morar
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, I tried this:
Path path = Paths.get("file_path"); // e.g. file_path(String): c:\\exdatis\\etc...
BasicFileAttributes attr;
try {
attr = Files.readAttributes(path, BasicFileAttributes.class);

System.out.println("Creation date: " + attr.creationTime());

} catch (Exception e) {
System.out.println( e.getMessage());
}

I think it's ok on win OS, but not with Linux, also there is need(nio):
import java.nio.file.Files;
import java.nio.file.attribute.BasicFileAttributes;
Is there something different, to find date creation of file? Some simple way?
Thank you very much and best regards!


 
Jesper de Jong
Java Cowboy
Sheriff
Posts: 16028
87
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Not all filesystems support this feature, so it is possible that this doesn't return the true creation date of the file. Apparently the Linux version and filesystem you are using does not support this. If the filesystem does not store this information, then there's no way to know it, because the information simply isn't stored on the disk.

Note that the API documentation already mentions this:
If the file system implementation does not support a time stamp to indicate the time of last modification then this method returns an implementation specific default value, typically a FileTime representing the epoch (1970-01-01T00:00:00Z).

 
Z Morar
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Jesper de Jong wrote:Not all filesystems support this feature...

That's it.
Thank you very much!

p.s. XUbuntu 14.04 32 bit - returns last modified date...
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!