2

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.

2

1 Answer 1

2

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.

Sign up to request clarification or add additional context in comments.

2 Comments

Will java7 be able to give file creation time in linux??
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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.