I need to get file creation date in linux machine using java. Many workarounds worked good in windows but failed in linux. Need a way to get file creation time in linux. Please note that my linux machine has java6 installed. Any help is much appreciated. Thanks in adavance.
-
1http://www.mkyong.com/java/how-to-get-the-file-last-modified-date-in-java/ Even though the example is for Windows OS, surely it would work for linux... – Ben Dale Aug 30 '13 at 09:38
-
possible duplicate of [Determine file creation date in Java](http://stackoverflow.com/questions/2723838/determine-file-creation-date-in-java) – RossC Aug 30 '13 at 09:39
1 Answers
You can use stat
command in Linux to get various date though creation date isn't available.
Instead you can get these 3 dates about a file:
- Time of last access
- Time of last modification (content of the file)
- Time of last change (metadata of file)
EDIT:
For getting creation/modification times of a file in Java (if using JDK 1.7) see: http://docs.oracle.com/javase/tutorial/essential/io/fileAttr.html
As per this document:
A word about time stamps: The set of basic attributes includes three time stamps: creationTime, lastModifiedTime, and lastAccessTime. Any of these time stamps might not be supported in a particular implementation, in which case the corresponding accessor method returns an implementation-specific value.
Unfortunately Linux/Unix doesn't store file's creation time hence you cannot get it.
PS: If you can use ext4 filesystem
then you can get file's creation time in Unix/Linux.

- 761,203
- 64
- 569
- 643
-
-
Javadoc says: `A word about time stamps: The set of basic attributes includes three time stamps: creationTime, lastModifiedTime, and lastAccessTime. Any of these time stamps might not be supported in a particular implementation, in which case the corresponding accessor method returns an implementation-specific value.` Which means if filesystem doesn't support it then it cannot get it. You can try though. – anubhava Aug 30 '13 at 09:55