SpringBoot下载文件,文件名带了中文出现乱码:
代码如下:
return ResponseEntity.ok()
.header("Content-disposition", "attachment;filename=" + fileName)
.contentLength(file.length())
.contentType(MediaType.parseMediaType("application/octet-stream"))
.body(resource);
解决办法:给文件名进行编码:
fileName = new String(fileName.getBytes("UTF-8"),"ISO-8859-1");
问题解决:
参考:SpringBoot下载文件【ResponseEntity,可支持指定中文文件名,防止文件名乱码】_can_sheng的博客-CSDN博客