You need a zip implementation when you do something before, the first thing to know is that the ant package's Zip package implements support for the Chinese pathname, and feels that the other should be the same as the zip util in the package, but it's a bit awkward to write, after all, it doesn't provide the Zipinputstream class, Therefore, we have to use getetries to get the entity set of enumerated type, its disadvantage is that it destroys the cascade relationship between entities, so it is not easy to deal with the Util.zip package.
Code a bit of a patchwork of ingredients, it is a paste it, hehe!!!
Import java.io. * ;
Import java.util. * ;
Import Org.apache.tools.zip.ZipEntry;
Import Org.apache.tools.zip.ZipFile;
Public class Unzip ... {
//zipfilename for the zip file that needs to be unzipped, extplace for the storage path of the extracted file, both must already exist
Public Static voidextzipfilelist (String zipfilename, string extplace)throws
Exception...{
ZipFile ZipFile= NewZipFile (zipfilename);
Enumeration e=Zipfile.getentries ();
ZipEntry ZipEntry= NULL;
while(E.hasmoreelements ())...{
ZipEntry=(ZipEntry) e.nextelement ();
String EntryName=Zipentry.getname ();
String names[]=Entryname.split ("/");
intlength=names.length;
String Path=Extplace;
for (intv= 0; v<length; v++) ...{
if(v<length- 1) ...{
Path + + names[v] + "/";
New File (path). mkdir ();
}
Else ...{ //last one
if(Entryname.endswith ("/")) ... { // for directory, create folder
New File (extplace + entryname). mkdir ();
}
Else ...{
InputStream in=Zipfile.getinputstream (ZipEntry);
OutputStream OS= NewFileOutputStream (NewFile (Extplace+
EntryName));
byte[] buf= New byte[1024];
intLen;
while((Len=In.read (BUF))> 0) ...{
Os.write (buf, 0, Len);
}
In.close ();
Os.close ();
}
}
}
}
Zipfile.close ();
}
}