class.getResource()和getResourceAsStream乱码有关问题
class.getResource()和getResourceAsStream乱码问题
getResource方法使用了utf-8对路径信息进行了编码,当路径中存在中文和空格时,他会对这些字符进行转换,这样,得到的往往不是我们想要的真实路径,在此,调用了URLDecoder的decode方法进行解码,以便得到原始的中文及空格路径。
String configPath = this.getClass().getClassLoader().getResource("allowPath.xml").getFile();
configPath = java.net.URLDecoder.decode(configPath,"utf-8");