java 中文路径FileNotFoundException
问题
java 中文路径FileNotFoundException
getClass().getClassLoader().getResource(template).getPath()
上面代码获取到的文件路径中如果出现了中文默认是会url编码的,这样就会出现filenotfound异常
解决
对路径进行url解码即可。
try {
templateFile = java.net.URLDecoder.decode(templateFile, "UTF-8");
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}