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,见鬼了~

解决方案 »

  1.   

    不管文件存在不存在,listFile.toString());都会返回路径的,所以第一个debug,总是会输出路径的
    然后你copy输出的路径,看看文件是否存在
    如果真的存在,就check一下有没有访问权限,没有访问权限的话,同样返回不存在false
      

  2.   

    是不是你的文件存放的路径有空格或者什么符号
    有的话需要解码才能得到正确路径URLDecoder.encode("path","GBK");