@RequestMapping(value = "/statement/downFile.action")
public void downloadFile(@RequestParam String filePath, HttpServletRequest request, HttpServletResponse response) throws Exception {
File reportFile = null;
try {
if (filePath == null || filePath.length() == 0)
return;
OutputStream output = response.getOutputStream();
reportFile = new File(filePath);
response.setCharacterEncoding("utf-8");
response.setContentType("application/octet-stream");
response.setHeader("Content-disposition", "attachment; filename="
+ new String("小区统计.xls".getBytes("utf-8"), "ISO8859-1"));
response.setHeader("Content-Length", String.valueOf(reportFile.length()));
FileInputStream fis = new FileInputStream(reportFile);
byte[] b = new byte[1024];
int i = 0;
while((i=fis.read(b))>0)
output.write(b,0,i);
output.flush();
fis.close();
output.close();
} catch (Exception e) {
Logger.getLogger(this.getClass().getName()).error(e);
e.printStackTrace();
}finally{
if(reportFile != null)
reportFile.delete();
}
}