This is crazy. A java program is failing in the simplest way imaginable. It looks for its configuration file located in ${user.home} from System properties. I log where the program is looking for the file, and have verified that the file it is looking for does in fact exist and that it's in the right place. But when the program runs, it fails to find the configuration file (checking first with `File.exists()). This is on a PC running Windows 7. The same program runs without this happening on a number of other PCs running either Windows 7 or XP.
At first, I thought the fact that I was running this program using Remote Desktop Connection from an XP box could possibly be significant. There are some Google hits pertaining to this on .NET file.exists(). However, when my colleague goes directly to the PC in question and attempts to run the program locally, the same thing happens.
I am stumped. Anyone have any ideas?
Here is the code:
static private File configDir = new File(System.getProperty("user.home"));
File configFile = new File(configDir, fileName);
log.debug("config file directory is " + configDir);
if (configFile.exists()) {
...
} else {
log.info("Override Configuration from File System not found.");
}
I had this problem while coding an interview solution and it turned out to be due to the fact that the file was actually called
foo.txt.txt
but showed up as:
foo.txt.
I have a strong suspicion that either this is or the permissions issue mentioned in the comments above is causing this issue. But if you can open the file as the same user that the Java program executes as, then you can rule out the permissions issue. In Windows you can click a checkbox that shows the file extensions. Here's a link that demonstrates how to toggle this behaviour.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With