我的webapp使用Spring MVC。下面的端点允许用户下载文件。当用户将该文件(Chrome,MSIE)保存在浏览器中时,该文件已损坏。它的大小是28792字节而不是24567,内容似乎有不同的编码。我花了一天的时间试图解决这个问题,但没有成功。源文件工作正常。请指教。非常感谢!为什么下载的文件已损坏?
@RequestMapping(method = POST, consumes = MULTIPART_FORM_DATA_VALUE)
public void processFile(MultipartFile file, HttpServletResponse response) {
try {
response.setHeader("Content-Encoding","UTF-8");
Files.copy(Paths.get("c:\\files", "worksheet.xls"), response.getOutputStream());
response.getOutputStream().flush();
} catch (Exception ignore) {
}
}