zoukankan      html  css  js  c++  java
  • org.dom4j.DocumentException: null Nested exception: null解决方法

    由于最近在学习使用spring架构,经常会遇到与xml文档打交道,今天遇到了此问题,特来分享一下解决方案。

    出错原因:

    很明显是因为找不到文件路径。这个原因是因为我使用了*.clas.getResourceAsStream(xmlFilePath)来进行xml文档的路径提供。使用这个方法时,对xml文档的路径安放有一定要求,只能在当前路径下进行搜索,不能使用绝对路径和相对路径,所以安放路径不正确就会产生这个异常。

    解决方法:

    第一种:

    将xml文件放到src文件夹下即可。

    第二种:

    public static Document parse2Document(String xmlFilePath)throws Exception{

    SAXReader reader = new SAXReader();

    Document document = null;

    File f = new File(xmlFilePath);

    InputStream in = new FileInputStream();

    document = reader(in);

    return document;

    }

  • 相关阅读:
    OS-lab4
    OS-lab3
    OS-lab2
    OS-lab1
    OO第四单元总结
    OO第三单元总结
    OO第二单元总结
    HTTP_POST
    实习日志1(2020.7.27-2020.9.31)
    Web app ------ 从Servlet读取Json数据并显示,生成历史数据曲线图
  • 原文地址:https://www.cnblogs.com/sharpest/p/6255963.html
Copyright © 2011-2022 走看看