本文共 605 字,大约阅读时间需要 2 分钟。
利用getResources可以使用classLoader查找当前项目的classpath下,所有的jar包路径
public class Test { public static void main(String[] args) throws Exception{ ClassLoader classLoader = Test.class.getClassLoader(); //只能搜索jar包内的字符,比如文件夹org,com,文件名a.xml Enumerationpaths = classLoader.getResources("META-INF"); int count = 0; while (paths.hasMoreElements()){ String path = paths.nextElement().toString(); if (path.indexOf("jdk") == -1){ count++; System.out.println(path); } } System.out.println(count); }}
转载地址:http://mrxlf.baihongyu.com/