1.首先从前台页面传递回来文件的具体位置 例如D://...
2
代码如下
@RequestMapping("/downloadRecruitInformation")
public ResponseEntity<byte[]> downloadRecruitInformation(String path) throws IOException{
//处理显示中文文件名的问题
File file = new File(path);
String fileName = new String(file.getName().getBytes("utf-8"),"ISO-8859-1");
//设置请求头内容,告诉浏览器代开下载窗口
HttpHeaders headers = new HttpHeaders();
headers.setContentType(MediaType.APPLICATION_OCTET_STREAM);
headers.setContentDispositionFormData("attachment",fileName);
/*前端弹出下载*/
return new ResponseEntity<byte[]>(FileUtils.readFileToByteArray(file),
headers, HttpStatus.CREATED);
}