Server zip package download

Source: Internet
Author: User

In the past few days, one click operation needs to generate downloads of multiple files, which is theoretically not feasible. A request must have only one response. Therefore, You Need To package multiple files into a zip package before downloading them. After searching the Internet, you can use the ZipOutputStream class. At the beginning, the author did not know how to use java.util.zip. ZipOutputStream. Later, I found that although the generated files are not garbled on the server end, after the files are added to the zip package, they are downloaded from the client, the obtained Chinese file names are garbled. So I thought it would be okay to change the encoding. After a few days, I found that java.util.zip. ZipOutputStream lacks encoding conversion. Chinese garbled characters cannot be solved. Search again and find that apachealso has an org.apache.tools.zip. ZipOutputStream. The method declaration is the same. So I changed the Reference Path of the class and ran it. Success !!!!

 

Mark usage

String zipfilename = "result.zip" String zipfilepath = storagePath + ZipOutputStream zos = ZipOutputStream (! File. exists () {BufferedWriter bw = BufferedWriter (OutputStreamWriter (FileOutputStream (file), "UTF-8"); bw. write (sb. toString (); ZipEntry ze = ZipEntry (file. getName (); BufferedInputStream bis = BufferedInputStream (len = bis. read (buf)> 0 zos. write (buf, 0 zos. close (); View Code

 

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.