getClassLoader() 的getResource 中文

2017-10-27  本文已影响0人  左洁

URL url =this.getClass().getClassLoader().getResource("/"+ basePackageName.replaceAll("\\.","/"));

String pathFile = url.getFile();  //如果是中文路径 pathfile是路径里面是乱码

//需要进行decode才能正常显示中文路径

String urlPath=java.net.URLDecoder.decode(pathFile,"utf-8");

参考链接  http://blog.sina.com.cn/s/blog_67cc72cc0101ejie.html

上一篇下一篇

猜你喜欢

热点阅读