当前位置: 代码迷 >> 综合 >> Springboot 、SpringMVC 浏览器下载文件中文文件名称乱码处理(包括ie浏览器)
  详细解决方案

Springboot 、SpringMVC 浏览器下载文件中文文件名称乱码处理(包括ie浏览器)

热度:95   发布时间:2024-03-08 10:42:12.0
/*** desc:* param:* return:* author: CDN* date: 2020/10/26*/@GetMapping("download")public void aa(HttpServletResponse response, HttpServletRequest request) throws IOException {File file = new File("C:\\Users\\ht\\Desktop\\这是一个需要下载的文件.xlsx");OutputStream out = response.getOutputStream();String fileName = "中文的文件名称.xlsx";response.setContentType("application/octet-stream");String s = dealFileName(request,fileName);response.setHeader("Content-Disposition", "attachment;filename=" + s);byte[] bytes=new byte[1024];int a=-1;FileInputStream fileInputStream = new FileInputStream(file);while ( ( a=fileInputStream.read(bytes)) != -1) {out.write(bytes,0, a);}out.flush();}/*** 处理IE/E
  相关解决方案