你看能不能先取到服务器地址加文件名看看

File file = new File("E:/temp/ccctc.application");
这句话改下
public static final String PROPERTIES_FILE_NAME = "/ccctc.application";
path = this.getClass().getResource("").getPath();
        int pos = path.indexOf("WEB-INF");
        path = path.substring(0, pos)+"WEB-INF\\classes";
file = new File(path, PROPERTIES_FILE_NAME);
把文件放到web-inf/classes 的目录下面我想应该不会在出现这样的问题了

解决方案 »

  1.   

    谢谢你的回复,这个xml文件(ccctc.application)本身是可以找得到的,只是在解析这个xml文件的时候,由于有头部的DTD定义,所以有错误(网络访问错误)。你的这种做法会对解析XML的过程产生影响吗?而且我解析这个xml的程序,并非servlet,所以this.getClass().getResource("").getPath()的结果中不会有“WEB-INF”这样的字符串。
      

  2.   

    多谢各位,问题已解决,其实也是在这里搜索得到的结果,不过找了好久,才找到:用DOM4J,定义一个EntityResolverpublic class NoopEntityResolver implements EntityResolver { /**
     * @see org.xml.sax.EntityResolver#resolveEntity(java.lang.String, java.lang.String)
     */
    public InputSource resolveEntity(String publicId, String systemId)
    throws SAXException, IOException {
    return new InputSource(new StringBufferInputStream(""));
    }}然后reader.setEntityResolver(new NoopEntityResolver());即可。