/**
* Decompress the compressed file containing folders.
*
* @ Param zipFile
* @ Param folderPath
* @ Throws ZipException
* @ Throws IOException
*/
Public void upZipFile (File zipFile, String folderPath) throws ZipException,
IOException {
File desDir = new File (folderPath );
If (! DesDir. exists ()){
// Create the target directory
DesDir. mkdirs ();
}
ZipFile zf = new ZipFile (zipFile );
For (Enumeration <?> Entries = zf. entries (); entries. hasMoreElements ();){
ZipEntry entry = (ZipEntry) entries. nextElement ());
If (entry. isDirectory ()){
String tmpStr = folderPath + File. separator + entry. getName ();
TmpStr = new String (tmpStr. getBytes ("8859_1"), "GB2312 ");
File folder = new File (tmpStr );
Folder. mkdirs ();
} Else {
InputStream is = zf. getInputStream (entry );
String str = folderPath + File. separator + entry. getName ();
// Convert the encoding to avoid Chinese garbled characters
Str = new String (str. getBytes ("8859_1"), "GB2312 ");
File desFile = new File (str );
If (! DesFile. exists ()){
// Create the target file
DesFile. createNewFile ();
}
OutputStream OS = new FileOutputStream (desFile );
Byte [] buffer = new byte [1024];
Int realLength;
While (realLength = is. read (buffer)> 0 ){
OS. write (buffer, 0, realLength );
OS. flush ();
}
Is. close ();
OS. close ();
}
}
Zf. close ();
}
/**
* Decompress a compressed package without folders
*
* @ Param zipFile
* @ Param folderPath
* @ Throws ZipException
* @ Throws IOException
*/
Public void upZipFile (File zipFile, String folderPath) throws ZipException,
IOException {
File desDir = new File (folderPath );
If (! DesDir. exists ()){
// Create the target directory
DesDir. mkdirs ();
}
ZipFile zf = new ZipFile (zipFile );
For (Enumeration <?> Entries = zf. entries (); entries. hasMoreElements ();){
ZipEntry entry = (ZipEntry) entries. nextElement ());
InputStream is = zf. getInputStream (entry );
String str = folderPath + File. separator + entry. getName ();
// Convert the encoding to avoid Chinese garbled characters
Str = new String (str. getBytes ("8859_1"), "GB2312 ");
File desFile = new File (str );
If (! DesFile. exists ()){
File fileParentDir = desFile. getParentFile ();
If (! FileParentDir. exists ()){
// Create the parent directory of the target file
FileParentDir. mkdirs ();
}
// Create the target file
DesFile. createNewFile ();
}
OutputStream OS = new FileOutputStream (desFile );
Byte [] buffer = new byte [1024];
Int realLength;
While (realLength = is. read (buffer)> 0 ){
OS. write (buffer, 0, realLength );
OS. flush ();
}
Is. close ();
OS. close ();
}
Zf. close ();
}