Reputation: 2382
java.io.File doesn't provide a way to get a file's creation date. You can get file.lastModified, but not anything like dateCreated.
Java 7 adds the excellent java.nio.file package with access to date created, but it's not out yet.
My question: what's the best way to get a file's date created from Java on a UNIX/OSX system? I suppose it's executing a shell script, but my command line skills are pretty weak. So if shell scripting's the way to go, if you could provide a full example I'd be very grateful.
Thanks!
Upvotes: 1
Views: 1806
Reputation: 86838
From the command line, the easiest way to get the creation date is with mdls
. I think you'd want to do /usr/bin/mdls -name kMDItemFSCreationDate $filename
(where $filename
is the file you're asking about). You can specify multiple filenames, but that might make it harder to parse the output.
Upvotes: 2
Reputation: 1247
Unix doesn't have a "creation date". The only dates stored on files are modification date, which stores the time the file contents where changed; the access date, which stores the last time a file was read; and the "change date", which stores the last time the file's metadata was changed. (The metadata contains things like permission bits, ownership, etc.)
If you review the structure supported by the stat(2) API, you can see the three timespec's.
Upvotes: 2
Reputation: 1903
It actually depends on the file system, and most file systems don't provide such feature as storing a file "birth time". You need to check the filesystem.
Upvotes: 0