package com.chenhong;
import java.io.*;
import java.util.zip.ZipEntry;
import java.util.zip.ZipFile;
import java.util.zip.ZipInputStream;
public class ZipTest {
public static void main(String[] args) throws Exception {
try {
String fileName = "D:/Users/aa.zip";
readZipFile(fileName);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
public static void readZipFile(String file) throws Exception {
ZipFile zf = new ZipFile(file);
InputStream in = new BufferedInputStream(new FileInputStream(file));
ZipInputStream zin = new ZipInputStream(in);
ZipEntry ze;
while ((ze = zin.getNextEntry()) != null) {
//如果为文件夹则不需要处理
if (!ze.isDirectory()) {
System.err.println("file - " + ze.getName() + " : "+ ze.getSize() + " bytes");
long size = ze.getSize();
if (size > 0) {
BufferedReader br = new BufferedReader(
new InputStreamReader(zf.getInputStream(ze)));
String line;
while ((line = br.readLine()) != null) {
System.out.println(line);
}
br.close();
}
}
}
zin.closeEntry();
}
}
java 不需要解压zip,读取 zip 文件内的各种文件
最新推荐文章于 2024-04-10 14:21:32 发布