package com.jwis.katch;
import java.io.File;
import java.io.IOException;
import java.util.Enumeration;
import java.util.zip.ZipEntry;
import java.util.zip.ZipException;
import java.util.zip.ZipFile;
public class readZipFile {
public static void readZipFile2(File file) {
try {
ZipFile zipfile = new ZipFile(file); //创建ZipFile对象
System.out.println(zipfile.getName()); //打印Zip文件路径
System.out.println("ZIP条目数:" + zipfile.size()); //打印Zip文件条目数
Enumeration<? extends ZipEntry> en = zipfile.entries();
ZipEntry entry;
while(en.hasMoreElements()) {
entry = (ZipEntry) en.nextElement();
System.out.println(entry.getName());
}
zipfile.close();
}catch(ZipException e) {
System.out.println(file.getName() + "压缩文件错误");
}catch(IOException e) {
System.out.println(file.getName() + "读取文件时出错");
}
}
public static void main(String[] args) {
File fileTest = new File("D:\\11\\11.zip");
readZipFile2(fileTest);
}
}
网友评论