@RequestMapping("downloads.do")
public ResponseEntity<byte[]> downLoad(String fileName,HttpServletRequest request,HttpServletResponse response) throws IOException {
//获取下载路径
String path=request.getServletContext().getRealPath("/policeUpload");
//拼接路径
File file=new File(path, fileName);
//创建一个响应头
HttpHeaders headers=new HttpHeaders();
//设置内容类型
headers.setContentType(MediaType.APPLICATION_OCTET_STREAM);
//设置响应
headers.setContentDispositionFormData("attachment", fileName,Charset.forName("utf-8"));
//返回二进制的文件数据
return new ResponseEntity<byte[]>(FileUtils.readFileToByteArray(file),headers,HttpStatus.OK);
}
报错提示:
File 'D:\java\java\serivce\.metadata\.plugins\org.eclipse.wst.server.core\tmp0\wtpwebapps\poplice\policeUpload\å½æ°è¿åº¦.txt' does not exist