Java by API/java.util.jar/JarFile — различия между версиями
Admin (обсуждение | вклад) м (1 версия) |
|
(нет различий)
|
Версия 17:43, 31 мая 2010
JarFile: entries()
import java.io.IOException;
import java.util.Enumeration;
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();
System.out.println(name);
}
}
}
JarFile: getManifest()
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);
}
}
}
}
new JarFile(String name)
import java.io.FileOutputStream;
import java.io.OutputStream;
import java.util.jar.JarFile;
import java.util.jar.Pack200;
public class Main {
public static void main(String[] args) throws Exception {
OutputStream out = null;
JarFile f = new JarFile(args[0]);
Pack200.Packer packer = Pack200.newPacker();
out = new FileOutputStream(args[0] + ".pack");
packer.pack(f, out);
out.close();
}
}