Java解析xml檔案遇到“unknown protocol: c Nested exception: unknown protocol: c”問題的解決辦法
阿新 • • 發佈:2018-12-21
在寫畢設的時候在解析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();