@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
用utf8字符编码集
但是你的服务器不是utf8编码集 所以就报错了。
https://blog.csdn.net/loveaborn/article/details/44450873
在filter中添加相应过滤器
https://blog.csdn.net/m0_52613676/article/details/115253075
谢谢大佬 刚学没多久,tomcat我重新加了个编码好啦!!~
您好,我是有问必答小助手,您的问题已经有小伙伴解答了,您看下是否解决,可以追评进行沟通哦~
如果有您比较满意的答案 / 帮您提供解决思路的答案,可以点击【采纳】按钮,给回答的小伙伴一些鼓励哦~~
ps:问答VIP仅需29元,即可享受5次/月 有问必答服务,了解详情>>>https://vip.csdn.net/askvip?utm_source=1146287632