0
点赞
收藏
分享

微信扫一扫

java 中文路径FileNotFoundException

鱼板番茄 2022-01-20 阅读 76

问题

java 中文路径FileNotFoundException

	getClass().getClassLoader().getResource(template).getPath()

上面代码获取到的文件路径中如果出现了中文默认是会url编码的,这样就会出现filenotfound异常

解决

对路径进行url解码即可。

	try {
		templateFile = java.net.URLDecoder.decode(templateFile, "UTF-8");
	} catch (UnsupportedEncodingException e) {
		e.printStackTrace();
	}
举报

相关推荐

0 条评论