Use the ant package to decompress the ZIP file

Source: Internet
Author: User

 

The renewal package is convenient.

The Code is a bit confusing. You can turn it into a post !!!

Import java. Io .*;
Import java. util .*;
Import org.apache.tools.zip. zipentry;
Import org.apache.tools.zip. zipfile;

Public class unzip ...{
// Zipfilename is the ZIP file to be decompressed, and extplace is the storage path of the decompressed file. Both files must already exist.
Public static void extzipfilelist (string zipfilename, string extplace) throws
Exception ...{
Zipfile = new zipfile (zipfilename );
Enumeration E = zipfile. getentries ();
Zipentry = NULL;
While (E. hasmoreelements ())...{
Zipentry = (zipentry) E. nextelement ();
String entryname = zipentry. getname ();
String Names [] = entryname. Split ("/");
Int length = names. length;
String Path = extplace;
For (int v = 0; v <length; V ++ )...{
If (v <length-1 )...{
Path + = Names [v] + "/";
New file (PATH). mkdir ();
}
Else... {// last
If (entryname. endswith ("/")... {// is the directory, the folder is created.
New file (extplace + entryname). mkdir ();
}
Else ...{
Inputstream in = zipfile. getinputstream (zipentry );
Outputstream OS = new fileoutputstream (new file (extplace +
Entryname ));
Byte [] Buf = new byte [1, 1024];
Int Len;
While (LEN = in. Read (BUF)> 0 )...{
OS. Write (BUF, 0, Len );
}
In. Close ();
OS. Close ();
}
}
}
}
Zipfile. Close ();
}
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.