在springboot下打包文件夹并导出zip包代码如下
@ApiOperation(value="导出接口")
@RequestMapping(value="/export",method = RequestMethod.GET)
public void export(HttpServletRequest request, HttpServletResponse response) throws IOException{
OutputStream out = response.getOutputStream();
try {
response.setCharacterEncoding("UTF-8");
String path = searchService.export();
File file = new File(path);
byte[] data = getStream(path);
// 压缩包名称
String downloadName = file.getName();
response.setHeader("Content-Disposition",
"attachment;filename=" + URLEncoder.encode(downloadName, "utf-8"));
response.addHeader("Content-Length", "" + data.length);
response.setContentType("application/octet-stream;charset=UTF-8");