Java by API/java.util.jar/Attributes
Версия от 17:43, 31 мая 2010; (обсуждение)
Attributes: entrySet()
import java.io.IOException;
import java.util.Enumeration;
import java.util.jar.Attributes;
import java.util.jar.JarEntry;
import java.util.jar.JarFile;
public class Main {
public static void main(String[] args) throws IOException {
JarFile jf = new JarFile(args[0]);
Enumeration e = jf.entries();
while (e.hasMoreElements()) {
JarEntry je = (JarEntry) e.nextElement();
String name = je.getName();
Attributes a = je.getAttributes();
if (a != null) {
Object[] nameValuePairs = a.entrySet().toArray();
for (int j = 0; j < nameValuePairs.length; j++) {
System.out.println(nameValuePairs[j]);
}
}
}
}
}
Attributes: getValue(Name name)
import java.util.Iterator;
import java.util.Map;
import java.util.jar.Attributes;
import java.util.jar.JarFile;
import java.util.jar.Manifest;
public class Main {
public static void main(String[] argv) throws Exception {
JarFile jarfile = new JarFile("filename.jar");
Manifest manifest = jarfile.getManifest();
Map map = manifest.getEntries();
for (Iterator it = map.keySet().iterator(); it.hasNext();) {
String entryName = (String) it.next();
Attributes attrs = (Attributes) map.get(entryName);
for (Iterator it2 = attrs.keySet().iterator(); it2.hasNext();) {
Attributes.Name attrName = (Attributes.Name) it2.next();
String attrValue = attrs.getValue(attrName);
}
}
}
}