@ResponseBody
@RequestMapping("/download")
public String downloadFile(HttpServletResponse response) throws IOException {
File file = new File("D:\\iii\\11.xlsx");
System.out.println(file.length());
DataInputStream in = null;
OutputStream out = null;
response.reset();//
try {
response.setCharacterEncoding("UTF-8");
response.setHeader("Content-disposition", "attachment; filename=\"" + URLEncoder.encode("11.xlsx","UTF-8"));// 设定输出文件头
response.setContentType("application/octet-stream");// 定义输出类型
//输入流:本地文件路径
in = new DataInputStream(
new FileInputStream(new File("D:\\iii\\11.xlsx")));
//输出流
out = response.getOutputStream();
response.getOutputStream();
//输出文件
int bytes = 0;
byte[] bufferOut = new byte[1024];
while ((bytes = in.read(bufferOut)) != -1) {
out.write(bufferOut, 0, bytes);
}
}catch (Exception e){
e.printStackTrace();
}
return "成功";
}
poi生成的excel文件没有问题,下载也正常,但是文件会损坏,请问是什么问题啊,大神帮忙解答一下,不胜感激
是否是编码问题