首页 > 技术文章 > org.dom4j.DocumentException: unknown protocol: d Nested exception: unknown

henuyuxiang 2017-09-06 17:18 原文

最近用dom4j写了一个修改XML文件的小例子,抛出了如下异常:

org.dom4j.DocumentException: unknown protocol: d Nested exception: unknown protocol: d

在网上查了资料,问题的原因是Tomcat的安装路径有空格.d是Tomcat安装的盘符.
解决的办法有两种:
1.重新安装Tomcat.去掉空格.


2.将解析的XML文档转换为File类型.

原始代码:

String path = "D:\\config.xml";
SAXReader reader = new SAXReader();
Document document = reader.read(path);

目的代码:

String path = "D:\\config.xml";
File file = new File(path);
SAXReader reader = new SAXReader();
Document document = reader.read(file);  

推荐阅读