Package and download files, package and download files

Source: Internet
Author: User

Package and download files, package and download files
CdncontractbillDAO billDAO = new CdncontractbillDAO (); List billlist = billDAO. findAll (); // the ZIP File to be downloaded. Its name is download.zip File zipFile = new File (System. getProperty ("cdncharge_pdf") + "DownLoad.zip"); try {// use this to construct the output stream ZipOutputStream zipoutStream = new ZipOutputStream (new FileOutputStream (zipFile); InputStream is; byte [] bufferArea = new byte [1024]; // read/write buffer // loop all files, package the file for (Object bi: billlist) {Cdnc Ontractbill bill = (Cdncontractbill) bi; File file = new File (bill. getPath (); if (file. exists () {FileInputStream zipinSource = new FileInputStream (file); int read = 0; ZipEntry zipEntry = new ZipEntry (file. getName (); zipoutStream. putNextEntry (zipEntry); // locate the location of the compressed entry and write the file to the compressed package while (read = zipinSource. read (bufferArea, 0, 1024 ))! =-1) {zipoutStream. write (bufferArea, 0, read);} zipoutStream. closeEntry (); zipinSource. close () ;}} zipoutStream. close (); is = new FileInputStream (zipFile); Filedownload. save (is, "", zipFile. getName ();} catch (Exception e) {e. printStackTrace ();} // Delete the generated ZIP file. delete ();

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.