需要一个xml解析器,比如xerces在apache.org可以得到,放到classpath

解决方案 »

  1.   

    哦?
    谢谢了。可以放在/jre/lib/ext下吗?
      

  2.   

    错误是什么?
    我也用过,并没有放到jdk下面,只是在project的lib下,没有任何问题。
      

  3.   

    你没有捕获异常。  public static Document readfromfile(String filePath) {
        try {
          java.io.File XmlFile;
          String XmlFileName;
          XmlFile = new java.io.File(filePath);
          SAXBuilder builder = new SAXBuilder();
          Document anotherDocument = builder.build(new File(filePath));
          return anotherDocument;
        }
        catch (JDOMException e) {
          e.printStackTrace();
        }
        catch (NullPointerException e) {
          e.printStackTrace();
        }
        catch (IOException e) {
          e.printStackTrace();
        }
        return null;
      }