zoukankan      html  css  js  c++  java
  • 打包并下载文件

      CdncontractbillDAO billDAO = new CdncontractbillDAO();
        List billlist = billDAO.findAll();
    //要下载的zip文件,名为DownLoad.zip
    File zipFile = new File(System.getProperty("cdncharge_pdf")+"DownLoad.zip");
        try {
    //用这个构造最终压缩包的输出流 
        ZipOutputStream zipoutStream = new ZipOutputStream(new FileOutputStream(zipFile));
        InputStream is;
        byte[] bufferArea = new byte[1024];//读写缓冲区
    //循环所有文件,将文件打包
      for(Object bi : billlist){
          Cdncontractbill 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);//定位到该压缩条目位置,开始写入文件到压缩包中
    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();
    }
        //删除生成的打包文件
        zipFile.delete();
  • 相关阅读:
    gulp+browser-sync使用方法
    小程序试用体验
    移动端调试总结
    函数防抖和函数分流
    页面返回顶部的方法总结
    POJ
    POJ
    UVA 10129 Play on Words(欧拉道路)
    UVA 10305 Ordering Tasks (拓扑排序)
    UVA 12657 Boxes in a Line(双向链表+小技巧)
  • 原文地址:https://www.cnblogs.com/kisstear/p/4789123.html
Copyright © 2011-2022 走看看