文件下载成功,但我无法打开文件,似乎已损坏。不知道我遗漏了什么。
public StreamingResponseBody getStreamingFile() throws IOException {
response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
response.setHeader("Content-Disposition", "attachment; filename=\"discrepancyReport.xls\"");
InputStream inputStream = new FileInputStream(new File(rootPath + ".xlsx"));
return outputStream -> {
int nRead;
byte[] data = new byte[4096];
while ((nRead = inputStream.read(data, 0, data.length)) != -1) {
outputStream.write(data, 0, nRead);
}
inputStream.close();
};
答案 0 :(得分:0)
问题似乎是招摇。当我尝试直接点击终点时,它按预期工作。