`

获取类根路径及jar包路径

 
阅读更多
public File  getClassRootDir(Class classz){
   String filePath = classz.getProtectionDomain().getCodeSource().getLocation().getFile();
   return  new File(filePath);
}
public File getJarFile(Class classz){
    String filePath = classz.getProtectionDomain().getCodeSource().getLocation().getFile();
    return  new File(filePath);
}
分享到:
评论
1 楼 QuarterLifeForJava 2016-05-27  
如果带有中文路径的话要写为:
URLDecoder.decode(filePath,"UTF-8")

相关推荐

Global site tag (gtag.js) - Google Analytics