views:

3597

answers:

4

Is there an easy way to discover a File's creation time with Java? The File class only has a method to get the "last modified" time. According to some resources I found on Google, the File class doesn't provide a getCreationTime() method because not all file systems support the idea of a creation time.

The only working solution I found involes shelling out the the command line and executing the "dir" command, which looks like it outputs the file's creation time. I guess this works, I only need to support Windows, but it seems very error prone to me.

Are there any third party libraries that provide the info I need?

Update: In the end, I don't think it's worth it for me to buy the third party library, but their API does seem pretty good so it's probably a good choice for anyone else that has this problem.

+1  A: 

Wfile

If you're only working with windows files it looks like this may work for you. It looks like it costs 1 dollar, but that may be worth it to you.

The other option is to the one you already mentioned. Shell out and do a dir.

ScArcher2
+1  A: 

I like the answer on jGuru that lists the option of using JNI to get the answer. This might prove to be faster than shelling out and you may encounter other situations such as this that need to be implemented specifically for windows.

Also, if you ever need to port to a different platform, then you can port your library as well and just have it return -1 for the answer to this question on *ix.

Joseph Gordon
+1  A: 

I've been investigating this myself, but I need something that will work across Windows/*nix platforms.

One SO post includes some links to Posix JNI implementations.

In particular, JNA-POSIX implements methods for getting file stats with implementations for Windows, BSD, Solaris, Linux and OSX.

All in all it looks very promising, so I'll be trying it out on my own project very soon.

Mike Houston
+1  A: 
LiuYan 刘研