Spring下载文件
@RequestMapping(value="download")
public String downloads(HttpServletResponse response , HttpServletRequest request) throws Exception{
String path = request.getServletContext().getRealPath("/upload");
String fileName = "上机实践报告模板.doc";
response.reset();
response.setCharacterEncoding("UTF-8");
response.setContentType("multipart/form-data");
response.setHeader("Content-Disposition",
"attachment;fileName="+ URLEncoder.encode(fileName, "UTF-8"));
File file = new File(path,fileName);
InputStream input=new FileInputStream(file);
OutputStream out = response.getOutputStream();
byte[] buff =new byte[1024];
int index=0;
while((index= input.read(buff))!= -1){
out.write(buff, 0, index);
out.flush();
}
out.close();
input.close();
return null;
}