下载

@RequestMapping("download")
public void download(String
fileName,HttpServletResponse res,HttpServletRequest
req) throws IOException{
//设置响应流中文件进行下载
res.setHeader("Content-Disposition",
"attachment;filename="+fileName);
//把二进制流放入到响应体中.
ServletOutputStream os = res.getOutputStream();
String path =
req.getServletContext().getRealPath("files");
System.out.println(path);
File file = new File(path, fileName);
byte[] bytes =
FileUtils.readFileToByteArray(file);
os.write(bytes);
os.flush();
os.close();
}
原文地址:https://www.cnblogs.com/chyxOne/p/11104060.html