当前位置: 代码迷 >> 综合 >> Java解析xml文件遇到“unknown protocol: c Nested exception: unknown protocol: c”问题的解决办法
  详细解决方案

Java解析xml文件遇到“unknown protocol: c Nested exception: unknown protocol: c”问题的解决办法

热度:67   发布时间:2023-12-16 00:08:15.0

在写毕设的时候在解析XML文件的时候遇到的一个棘手的问题“unknown protocol: c Nested exception: unknown protocol: c”,翻阅了资料说是tomcat的安装路径不能有空格,要么重新安装tomcat,要么以文件的形式进行解析,果断选择第二种,结果如下:

原先的代码:

String path = getServletContext().getRealPath("/cities.xml");
SAXReader reader = new SAXReader();
Document document = reader.read(path);
String xmlText = document.asXML();

修改后的代码如下:

String path = getServletContext().getRealPath("/cities.xml");
SAXReader reader = new SAXReader();
File file = new File(path);
Document document = reader.read(file);
String xmlText = document.asXML();