package ccc.my;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.zip.ZipEntry;
import java.util.zip.ZipInputStream;
public class Juneibulei {
public static void jieyacaozuo() throws IOException {
int hc = -1;
byte jyhcq[] = new byte[Byte.MAX_VALUE];// 因为我认为为hc分配了内存如果不去沾满它感觉浪费了,物尽其用嘛
File ywj = new File("E:\\明日科技教程\\java开发资源库.zip");// 要读取源文件对象引用
ZipInputStream hi = new ZipInputStream(new FileInputStream(ywj));// 实例化zip流入流,用来读取压缩包压缩数据
FileOutputStream xieru = null;// 将hi读取的数据(已加压的)写入解压路径
ZipEntry duqutiaomu = null;// 设立对象引用但为调用其构造方法为其分配内存,所以设立为null
while (true) {
duqutiaomu = hi.getNextEntry();// 循环读取一个条目,
if (duqutiaomu == null) {
System.out.println("因为为空包所以无法解压");
break;
} else if (!(duqutiaomu.isDirectory())) {
continue;
} else {
File ls = new File("D:\\" + ywj.getName() + duqutiaomu.getName());
if (!(ls.exists())) {
ls.mkdirs();
}
xieru = new FileOutputStream(ls);
while ((hc = hi.read(jyhcq)) != -1) {
xieru.write(jyhcq, 0, hc);
xieru.flush();
}
}
hi.closeEntry();
xieru.close();
}
hi.close();
}
public static void main(String[] args) {
try {
jieyacaozuo();
} catch (Exception e) {
e.printStackTrace();
}
}//不知为什么会出现这个异常,以百度。这好像是非法参数异常但我愚钝看不出,请老师或大佬呈正谢谢
}异常信息:java.lang.IllegalArgumentException: MALFORMED
at java.util.zip.ZipCoder.toString(Unknown Source)
at java.util.zip.ZipInputStream.readLOC(Unknown Source)
at java.util.zip.ZipInputStream.getNextEntry(Unknown Source)
at ccc.my.Juneibulei.jieyacaozuo(Juneibulei.java:24)
at ccc.my.Juneibulei.main(Juneibulei.java:50)