getPath()返回路径包含的“%20”(空格)

来源:互联网 发布:网络电视能看电视台吗 编辑:程序博客网 时间:2024/06/09 20:58


this.getClass().getResource("").getPath()  获取文件路径时,若包含空格,url中则会出现'%20',

导致出现找不到路径的错误

解决方案:
可以把路径中包含中文问题一并处理掉

String configPath = java.net.URLDecoder.decode(this.getClass().getResource("").getPath(),"utf-8");
Document document = reader.read(new File(configPath+"\\channel.xml"));

原创粉丝点击