While using File.mkdir, and friends I notice that they don’t throw exceptions on failure! Thankfully FindBugs pointed this out and now my code at least checks the return value but I still see no way to get meaningful information about why the call fails!
How do I find out why calls to these File methods fail? Is there a good alternative or library that handles this?
I’ve done some searches here on SO and Google and found surprising little info on this topic.
[update] I’ve given VFS a try and its exception don’t have anymore useful information. For example trying to move a directory that had been recently deleted resulted in Could not rename file "D:\path\to\fileA" to "file:///D:/path/do/fileB". No mention that fileA no longer existed.
[update] Business requirements limit me to JDK 1.6 solutions only, so JDK 1.7 is out
You could call native methods, and get proper error codes that way. For example, the c function mkdir has error codes like EEXIST and ENOSPC. You can use JNA to access these native functions fairly easily. If you are supporting *nix and windows you will need to create two versions of this code.
For an example of jna mkdir on linux you can do this,