我可以在我的 java 程序中读取所有类路径 jar 的清单文件。但我想读取特定 jar 的 MANIFEST 文件说“xml-apis-1.0.b2.jar”怎么做?
我的工作代码是
Enumeration resEnum;
try{
resEnum =Thread.currentThread().getContextClassLoader().getResources(JarFile.MANIFEST_NAME);
while (resEnum.hasMoreElements()) {
try {
URL url = (URL)resEnum.nextElement();
InputStream is = url.openStream();
if (is != null) {
Manifest manifest = new Manifest(is);
Attributes mainAttribs = manifest.getMainAttributes();
String vendor = mainAttribs.getValue("Implementation-Vendor");
String version = mainAttribs.getValue("Implementation-Version");
if(!mainAttribs.getValue("Extension-Name").equals("null")){
System.out.println(mainAttribs.getValue("Implementation-Title"));
System.out.println(version);
System.out.println(vendor);
System.out.println(mainAttribs.getValue("Extension-Name"));
}
}
}catch(Exception e){}
}
}catch(Exception e){