Exception in thread "main" java.util.zip.ZipException: error in opening zip file
at java.util.zip.ZipFile.open(Native Method)
at java.util.zip.ZipFile.<init>(Unknown Source)
at java.util.zip.ZipFile.<init>(Unknown Source)
at java.util.zip.ZipFile.<init>(Unknown Source)
at demo.ZipFile01.main(ZipFile01.java:8)
代码:
import java.io.*;
import java.util.zip.*;
class ZipFile01{
public static void main(String args[])throws Exception{
File f=new File("D:"+File.separator+"mold.zip");//声明解压的对象
File Outputf=new File("D:"+File.separator+"moldy.txt");
ZipFile zipFile=new ZipFile(f);//实例化ZipFile对象
ZipEntry entry=zipFile.getEntry(f.getName());
OutputStream out=new FileOutputStream(Outputf);
InputStream input=zipFile.getInputStream(entry);//得到一个压缩实体
int temp=0;
while((temp=input.read())!=-1){
out.write(temp);
}
input.close();
out.close();
zipFile.close();
}
}
相关分类