This seems like a pretty straightforward question but I haven't been able to find a definitive answer anywhere online. How can I get the date/time a file was created through Java's file manager? Aside from just the name of a file, what else can I get about the file's "properties"?
The command is sudo debugfs -R 'stat /path/to/file' /dev/sdaX (replace sdaX with the device name of the filesystem on which the file resides). The creation time is the value of crtime . You can add | grep . [^ca]time to list just mtime (the modification time) and crtime (the creation time).
What the Create Date of a file is, is actually rather self-explanatory. It is basically just the date of creation of the file in question. The is often displayed in the date format given by the computer, device or machine that created the file.
Use getctime() function to get a creation time path. getmtime('file_path') function returns the creation time of a file. On the other hand, on Unix, it will not work. Instead, it will return the timestamp of the last time when the file's attributes or content were changed (most recent metadata change on Unix).
I'm not sure how you'd get it using Java 6 and below. With Java 7's new file system APIs, it'd look like this:
Path path = ... // the path to the file
BasicFileAttributes attributes =
Files.readAttributes(path, BasicFileAttributes.class);
FileTime creationTime = attributes.creationTime();
As CoolBeans said, not all file systems store the creation time. The BasicFileAttributes Javadoc states:
If the file system implementation does not support a time stamp to indicate the time when the file was created then this method returns an implementation specific default value, typically the last-modified-time or a FileTime representing the epoch (1970-01-01T00:00:00Z).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With