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

  

上一篇:response下载文件


下一篇:⑧RDD,DataFrame,DataSet对比