public String downReport() {
HttpServletResponse response = ServletActionContext.getResponse();BufferedOutputStream bos = null;
BufferedInputStream bis = null;
//传入所要下载的文件路径,中文需要编码处理
File file = new File(Contents.REPORT_PATH + reportPath);
try {
bos = new BufferedOutputStream(response.getOutputStream());
if (file.exists()) {
} else {
file.createNewFile();
}
bis = new BufferedInputStream(new FileInputStream(file));
response.setContentType("application/msword");
response.setHeader("Content-Disposition", "attachment;filename=\""
+ reportPath.substring(reportPath.lastIndexOf("/")) + "\"");
//
byte[] buff = new byte[2048];
int bytesRead;
while (-1 != (bytesRead = bis.read(buff, 0, buff.length))) {
bos.write(buff, 0, bytesRead);
}
} catch (final Exception e) {
System.out.println("³öÏÖIOException. " + e);
} finally {
try {
if (bis != null)
bis.close();
if (bos != null)
bos.close();
} catch (IOException e) {
e.printStackTrace();
}
}
return null;
}