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); }
获取类根路径及jar包路径
最新推荐文章于 2023-06-14 15:06:41 发布
本文提供了两个用于获取Java类文件所在目录及jar文件路径的方法。通过利用Class对象的getProtectionDomain()和getCodeSource().getLocation().getFile()方法组合,可以轻松地获取到类文件的具体路径。
923

被折叠的 条评论
为什么被折叠?



