@RequestMapping(value = "/downloadTemplate", method = RequestMethod.GET)
public void downloadTemplate(HttpServletResponse response, HttpServletRequest request) {
try {
InputStream resourceAsStream = this.getClass().getClassLoader().getResourceAsStream("template/ggsjxqmb.zip");
//获取要下载的模板名称
String fileName = "广告设计需求模板.zip";
response.setHeader("content-type", "application/octet-stream");
response.setContentType("application/octet-stream");
String encodeName = URLEncoder.encode(fileName, StandardCharsets.ISO_8859_1.toString());
response.addHeader("Cache-Control", "no-cache, no-store, must-revalidate");
response.addHeader("charset", "ISO_8859_1");
response.addHeader("Pragma", "no-cache");
response.setHeader("Content-Disposition", "attachment; filename=\"" + encodeName + "\"; filename*=ISO_8859_1''" + encodeName);
OutputStream out = response.getOutputStream();
byte[] b = new byte[2048];
int len;
while ((len = resourceAsStream.read(b)) != -1) {
out.write(b, 0, len);
}
out.close();
resourceAsStream.close();
} catch (Exception ex) {
ex.printStackTrace();
}
}
下载rsource下的文件
最新推荐文章于 2024-09-14 18:46:05 发布