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 ();