其他分享
首页 > 其他分享> > zip文件下载

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

  

标签:文件,String,zip,ZipEntry,response,下载,out
来源: https://www.cnblogs.com/banxia-boke/p/15838271.html