try {
//获取当前类所在路径
String path = new AlgApplicationTests().getClass().getProtectionDomain().getCodeSource().getLocation().getPath();
//解决中文路径
path = java.net.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包所在路径
最新推荐文章于 2024-07-07 11:37:35 发布