String fileAddress = this.getClass().getClassLoader()
.getResources("categoryList.xml").nextElement()
.getPath();
File listFile = new File(fileAddress);
logger.debug("Get the file at: " + listFile.toString());
categoryParser = new CategoryParser();
logger.debug("If file exists: " + listFile.exists());代码是在tomcat里运行的,配置文件的路径相对tomcat都是一样的,可在我自己的电脑上可以获取到文件(listFile.exists()返回true),其他人的电脑都返回false……
第一个debug输出都可以正确返回配置文件路径的。
我电脑是win7+jdk 1.6u20,见鬼了~
然后你copy输出的路径,看看文件是否存在
如果真的存在,就check一下有没有访问权限,没有访问权限的话,同样返回不存在false
有的话需要解码才能得到正确路径URLDecoder.encode("path","GBK");