java.lang.RuntimeException: org.dom4j.DocumentException: 系统找不到指定的路径

来源:互联网 发布:淘宝网旗袍服饰 编辑:程序博客网 时间:2024/06/03 20:15

报错信息:

java.lang.RuntimeException: org.dom4j.DocumentException:
F:\java%20eclipse\workspace\MVC\build\classes\users.xml (系统找不到指定的路径。) Nested exception: F:\java%20eclipse\workspace\MVC\build\classes\users.xml (系统找不到指定的路径。)

原因:

java中获取文件路径的时候,有时候会获取到空格,但是在中文编码环境下,空格会变成“%20”从而使得路径错误。

解决办法:

设置String的编码格式
filepath = URLDecoder.decode(filepath,”UTF-8”);

具体代码如:

 //获取xml    static{        filepath = XmlUtils.class.getClassLoader().getResource("users.xml").getPath();        try {            filepath = URLDecoder.decode(filepath,"UTF-8");        } catch (UnsupportedEncodingException e) {                      e.printStackTrace();        }    }
阅读全文
0 0
原创粉丝点击