Wednesday, September 28, 2011

Java 7, brings a simple yet a long awaited feature...

Would you be surprised to know that the API of only supported getting the last modified time, and NOT the file's creation time, until Java 7...? Well, not many people seem to be aware of this and surprisingly even the Internet was very quiet on this topic all the while.

So if you are using anything below Java 7 and are desperate to fetch a file's creation time then, one solution would be to write some native code to call system routines and then call the native code using JNI. Most of this work seems to be already done for you in a library called JNA, though. Nevertheless, you will still need to do a little OS specific coding in Java for this, though, as you'll probably not find the same system calls available in Windows and Unix/Linux/BSD/OS X.