失眠网,内容丰富有趣,生活中的好帮手!
失眠网 > Java获取jar包所在路径

Java获取jar包所在路径

时间:2019-10-29 23:49:04

相关推荐

Java获取jar包所在路径

try {//获取当前类所在路径String path = new AlgApplicationTests().getClass().getProtectionDomain().getCodeSource().getLocation().getPath();//解决中文路径path = .URLDecoder.decode(path,"UTF-8");//把路径切换到jar包所在位置File file = new File(path);path = file.getParentFile().getParentFile().getParentFile().getParent();//路径里可能会以file:\E:\xxx\ 显示 需要过虑出正确地址path = path.replace("file:\\","").replace("file:","");System.out.println(path);} catch (UnsupportedEncodingException e) {e.printStackTrace();}

如果觉得《Java获取jar包所在路径》对你有帮助,请点赞、收藏,并留下你的观点哦!

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。