获取lib同级文件路径

获取lib同级文件路径


  • 话不多说直接上代码

java.net.URL url = MyBatisGenerator.class.getProtectionDomain().getCodeSource().getLocation();
String filePath = null;
try {
filePath = java.net.URLDecoder.decode(url.getPath(), "utf-8");
// System.out.println("filePath1:"+filePath);
} catch (Exception e) {
e.printStackTrace();
}
if (filePath.endsWith(".jar"))
filePath = filePath.substring(0, filePath.lastIndexOf("/") + 1);
java.io.File file_temp = new java.io.File(filePath);
filePath = file_temp.getAbsolutePath();
// System.out.println("filePath2:"+filePath);
File configFile=new File(filePath+"\\generatorConfig.xml");

发布了12 篇原创文章 · 获赞 5 · 访问量 1万+

猜你喜欢

转载自blog.csdn.net/baidu_34569059/article/details/81452481