unable to validate directory loaded from property file
I am trying to load a directory from a properties file. I have the following defined in the property file:
image.src.dir = "C:\\Temp\\foo\\"
Yes,开发者_C百科 the directory name is like that ... with mixed case. I have also tried simply referring to the directory as "/Temp/foo"
with the same outcome.
I have the following code which fails despite the directory existing.
String srcDir = prop.getProperty("image.src.dir");
File folder = new File(srcDir);
if (!folder.isDirectory()) {
System.err.println("Directory: " + srcDir + " doesn't exist");
}
Thanks for the hint ...
The problem & solution:
solution: image.src.dir=C:\\Temp\\foo\\
problem: image.src.dir = "C:\\Temp\\foo\\"
That was my problem ..!
You have quotes in your property file. Quotes are needed for literal Strings in Java, but not Strings defined inside of a properties file.
Try this:
image.src.dir = C:\\Temp\\foo\\
Did you try to System.println(srcDir) if the string gets properly loaded from the properties file? Is the directory accessible (are the rights for superdirectories correct?).
精彩评论