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");
问题解决: