Android decompress the zip file (Chinese supported)

Source: Internet
Author: User

After more than n days, when I use the original blog article again:

Android compression and decompression zip file

When I decompressed the zip package, many problems were not found. The first is the problem of Chinese characters. The java zip package cannot solve the problem of decompression.

The judgment in getRealFileName:
If the preceding "if (dirs. length> 1)" is greater than 1, some files cannot be decompressed and changed:
If (dirs. length> 0)

If the zip package contains a Chinese directory or a Chinese file, refer to the resources on the Internet:
"Use the apache zip Toolkit (the package is ant. jar) replaces the JDK zip toolkit, because the java type does not support Chinese paths, but the two are used in the same way, but the apache compression tool has an interface for setting the encoding method, others are basically the same."

If you want to use apache in android, You need to import the ant. jar package. The download link is attached below:
Http://download.csdn.net/detail/shizhending/4139787

The following is an entry for how to add a jar package to an android project:
Http://hi.baidu.com/yore2003/item/fb6d5cd21a4bec4dddf9bef2

Note the following when adding a jar file:
Right-click the project and choose properties> Java Build Path> Order and Export.
Then place the Libray jar you just added to the top.

The following is the specific source code for using the apache zip Toolkit:
UnZipFile (String archive, String decompressDir) ZipFile zf = ZipFile (archive, "GBK" Enumeration e = ZipEntry ze2 = String entryName = String path = decompressDir + "/" + System. out. println ("creating extract directory-" + File decompressDirFile = (! } System. out. println ("creating the decompression File-" + String fileDir = path. substring (0, path. lastIndexOf ("/" File fileDirFile = (! BufferedOutputStream bos = BufferedOutputStream (FileOutputStream (decompressDir + "/" + bi = [] readContent = [1024 readCount = (readCount! =-1 bos. write (readContent, 0 readCount =}

Also remember to add permissions in AndroidManifest. xml.




Related Article

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.