Import java. Io. bufferedinputstream;
Import java. Io. bufferedoutputstream;
Import java. Io. file;
Import java. Io. fileoutputstream;
Import java. util. enumeration;
Import java.util.zip. zipentry;
Import java.util.zip. zipfile;
Public class zipper {
Static final int buffer = 2048;
Public static void main (string [] argv ){
Try {
String filename = "d :\\ lib.zip ";
String filepath = "d :\\";
Zipfile = new zipfile (filename );
Enumeration EMU = zipfile. Entries ();
Int I = 0;
While (EMU. hasmoreelements ()){
Zipentry entry = (zipentry) EMU. nextelement ();
// Read the directory as a file once, so you only need to create a directory, and the files under it will be iterated.
If (entry. isdirectory ()){
New file (filepath + entry. getname (). mkdirs ();
Continue;
}
Bufferedinputstream Bis = new bufferedinputstream (zipfile. getinputstream (entry ));
File file = new file (filepath + entry. getname ());
// The reason for this is that zipfile reads files randomly, which may first read a file.
// The directory where the file is located has not appeared, so you need to create a directory.
File parent = file. getparentfile ();
If (parent! = NULL &&(! Parent. exists ())){
Parent. mkdirs ();
}
Fileoutputstream Fos = new fileoutputstream (File );
Bufferedoutputstream Bos = new bufferedoutputstream (FOS, buffer );
Int count;
Byte [] DATA = new byte [buffer];
While (COUNT = bis. Read (data, 0, buffer ))! =-1 ){
Bos. Write (data, 0, count );
}
Bos. Flush ();
Bos. Close ();
Bis. Close ();
}
Zipfile. Close ();
} Catch (exception e ){
E. printstacktrace ();
}
}
}