下载

@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();
}

 

posted @ 2019-06-28 17:46  Aron_chen  阅读(96)  评论(0编辑  收藏  举报