// 译者注:enum 在 Java 5.0 中是关键字,所以该例在 5.0 中应该编译失败
// 但英文原著发表于 Java 5.0 出现之前,所以可以使用 enum 作变量名
// 为忠于原著,这里未作修改
Enumeration enum = jarFile.entries();
while (enum.hasMoreElements()) {
process(enum.nextElement());
}
import java.io.*;
import java.util.*;
import java.util.jar.*;
public class JarDir {
public static void main (String args[])
throws IOException {
if (args.length != 1) {
System.out.println("Please provide a JAR filename");
System.exit(-1);
}
JarFile jarFile = new JarFile(args[0]);
Enumeration enum = jarFile.entries();
while (enum.hasMoreElements()) {
process(enum.nextElement());
}
}
private static void process(Object obj) {
JarEntry entry = (JarEntry)obj;
String name = entry.getName();
long size = entry.getSize();
long compressedSize = entry.getCompressedSize();
System.out.println(name + " " + size + " " + compressedSize);
}
}
META-INF/MANIFEST.MF 5315 1910 META-INF/4JCEJARS.SF 5368 1958 META-INF/4JCEJARS.DSA 2207 1503 META-INF/ 0 2 javax/ 0 0 javax/crypto/ 0 0 javax/crypto/interfaces/ 0 0 javax/crypto/interfaces/DHKey.class 209 185 javax/crypto/interfaces/DHPublicKey.class 265 215 javax/crypto/interfaces/DHPrivateKey.class 267 215 javax/crypto/interfaces/PBEKey.class 268 224 javax/crypto/SecretKey.class 167 155 ...
import java.io.*;
import java.util.jar.*;
public class JarRead {
public static void main (String args[])
throws IOException {
if (args.length != 2) {
System.out.println("Please provide a JAR filename and file to read");
System.exit(-1);
}
JarFile jarFile = new JarFile(args[0]);
JarEntry entry = jarFile.getJarEntry(args[1]);
InputStream input = jarFile.getInputStream(entry);
process(input);
jarFile.close();
}
private static void process(InputStream input)
throws IOException {
InputStreamReader isr =
new InputStreamReader(input);
BufferedReader reader = new BufferedReader(isr);
String line;
while ((line = reader.readLine()) != null) {
System.out.println(line);
}
reader.close();
}
}
The itsy bitsy spider Ran up the water spout Down came the rain and Washed the spider out
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有