Skip to content
Advertisement

How to find file creation date in linux using java?

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.

Advertisement

Answer

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.

User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement