Copy codeThe Code is as follows: import java. io. File;
Import java. io. FileOutputStream;
Import java. io. IOException;
Import java. io. InputStream;
Import java. io. OutputStream;
Import java. util. Enumeration;
Import java.util.zip. ZipEntry;
Import java.util.zip. ZipFile;
Public class UnZipper {
/**
* The function of extracting files to the current directory is equivalent to right-clicking and extracting files
* @ Param zipFile
* @ Param
* @ Author gabriel
*/
@ SuppressWarnings ("rawtypes ")
Public static void unZipFiles (File zipFile) throws IOException {
// Obtain the directory of the compressed file
String path = zipFile. getAbsolutePath ();
Path = path. substring (0, path. lastIndexOf ("\\"));
// System. out. println ("path" + path );
ZipFile zip = new ZipFile (zipFile );
For (Enumeration entries = zip. entries ();
Entries. hasMoreElements ();){
ZipEntry entry = (ZipEntry) entries. nextElement ();
String zipEntryName = entry. getName ();
InputStream in = zip. getInputStream (entry );
// OutPath output directory
String outPath = (path + "\" + zipEntryName). replaceAll ("\\*","/");;
// System. out. println ("outPath" + outPath );
// Determine whether the path exists. If the path does not exist, create a file path.
File file = new File (outPath. substring (0, outPath. lastIndexOf ('/')));
If (! File. exists ()){
File. mkdirs ();
}
// Determine whether the full file path is a folder. If the file has been uploaded, you do not need to decompress the package.
If (new File (outPath). isDirectory ()){
Continue;
}
// Output file path information
System. out. println (outPath );
OutputStream out = new FileOutputStream (outPath );
Byte [] buf1 = new byte [1024];
Int len;
While (len = in. read (buf1)> 0 ){
Out. write (buf1, 0, len );
}
In. close ();
Out. close ();
}
System. out. println ***************** ***");
}
Public static void main (String [] args ){
Try {
UnZipFiles (new File ("D: \ all \ zip \ Default.adiumemoticonset.zip "));
} Catch (IOException e ){
// TODO Auto-generated catch block
E. printStackTrace ();
}
}
}