String path = "C:\\personal\\A.jar";
//读入一个jar包
JarFile jarFile = new JarFile(path);
Enumeration<JarEntry> jarEntries = jarFile.entries();
ClassFile cf;
String key = "println";
while (jarEntries.hasMoreElements()) {
JarEntry jarEntry = jarEntries.nextElement();
if (jarEntry.getName().contains(".class")) {
//判断是否为class文件
cf = ClassFile.read(jarFile.getInputStream(jarEntry));
//用constantpool查看class的内容
System.out.print(jarEntry.getName().toString());
for (int i = 1; i < cf.constant_pool.size(); i++) {
if (cf.constant_pool.get(i).toString().contains(key)) {
System.out.println(" has found " + key);
break;
} else if (i == cf.constant_pool.size()-1) {
System.out.println(" has not found " + key);
}
}
}
}
jarFile.close();
網上找了很多 最后看Api解決的 Jarfile 和Jarentry解決的
constantpool來自老師的提示
over
转载于:https://blog.51cto.com/9303206/1603126