zip文件下载

  记录一下zip压缩文件下载


  下载的内容有些大 ,通过变成.zip的文件的话会小很多,response是HttpServletResponse,记得关闭流

    //文件压缩下载
        ZipOutputStream out;
        String fileName = dataType + ".zip";

        response.reset();
        response.setHeader("content-type", "application/x-zip-compressed");
        response.setContentType("application/zip;charset=utf-8");
        response.setHeader("Content-Disposition", "attachment; filename=" + fileName);

        out = new ZipOutputStream(response.getOutputStream());
        ZipEntry entry = new ZipEntry(dataType + ".sql");
        out.putNextEntry(entry);

        //写值
        for (String s : list) {
            out.write(s.getBytes());
        }
        out.flush();
        out.close();

  

posted @ 2022-01-24 09:46  不是安逸  阅读(178)  评论(0编辑  收藏  举报