我们在通过类加载器ClassLoader获取目录下文件的path时:
String path = JsoupDemo01.class.getClassLoader().getResource("文件名").getPath();
如果对path不做后续处理,上述代码的出的url路径可能存在乱码
原因是文件路径中存在空格、中文字符等
解决方法:
URL的编码和解码的问题,地址用Encode编码要用与URLDecode进行解码
需要对path再进行一步处理
String path = JsoupDemo01.class.getClassLoader().getResource("文件名").getPath();
path = URLDecoder.decode(path, "utf-8");
此path就不会将空格和中文解码成乱码了
问题解决