/**
* 文件下载
*
*/
@RequestMapping("/downLoad")
public void downLoad(HttpServletRequest request,String filePath, HttpServletResponse response) throws Exception {
filePath = URLDecoder.decode(filePath, "UTF-8");
System.out.println(filePath);
filePath = request.getRealPath("\\")+filePath;
String fileName=filePath.substring(filePath.lastIndexOf("/")+1);
System.out.println(filePath);
File f = new File(filePath);
if (!f.exists()) {
response.sendError(404, "File not found!");
return;
}
BufferedInputStream br = new BufferedInputStream(new FileInputStream(f));
byte[] buf = new byte[1024];
int len = 0;
response.reset(); // 非常重要
response.setContentType("application/x-msdownload");
response.setHeader("Content-Disposition", "attachment; filename=" + new String((fileName).getBytes(),"iso8859-1"));
OutputStream out = response.getOutputStream();
while ((len = br.read(buf)) > 0)
out.write(buf, 0, len);
br.close();
out.close();
}
下载Excel文件模板 ---文件下载--SSM
最新推荐文章于 2022-01-15 09:23:21 发布