//生成2个text文件并压缩成zip文件返回给浏览器不生成临时文件 try { response.setContentType("application/octet-stream"); response.setHeader("Content-Disposition", "attachment; filename=" + URLEncoder.encode("test.zip", "UTF-8")); ZipOutputStream zos = new ZipOutputStream(response.getOutputStream()); ZipEntry zipEntry = new ZipEntry("test1.txt"); zos.putNextEntry(zipEntry); zos.write("test1".getBytes()); zos.closeEntry(); zipEntry = new ZipEntry("test2.txt"); zos.putNextEntry(zipEntry); zos.write("test2".getBytes()); zos.closeEntry(); zos.close(); } catch (IOException e) { e.printStackTrace(); }
生成2个text文件并压缩成zip文件返回给浏览器不生成临时文件
最新推荐文章于 2024-09-05 11:00:53 发布