try{
String fileName = GlobalConfig.getProperty("/file.properties", "CreditManageReportFileName");
String filename = "信用管理报告.docx";
InputStream fis = HttpDownloadUtil.class.getClassLoader().getResourceAsStream(fileName.toString());
XWPFDocument document = rebuildWord(fis,map);
OutputStream toClient = null;
try {
File file= new File(filename);
FileOutputStream fout = new FileOutputStream(file);
document.write(fout);
fout.close();
fis = new BufferedInputStream(new FileInputStream(file));
byte[] buffer = new byte[8 * 1024];
// 清空response
super.getResponse().reset();
// 设置response的Header
super.getResponse().setContentType("application/vnd.ms-excel;charset=UTF-8");
super.getResponse().setCharacterEncoding("UTF-8");
super.getResponse().addHeader("Content-Disposition",
"attachment;filename=" + new String(filename.getBytes("gb2312"), "ISO-8859-1"));
//super.getResponse().addHeader("Content-Length", "" + file.length());
super.getResponse().setHeader("content-Type", "application/msword");
toClient = new BufferedOutputStream(super.getResponse().getOutputStream());
int count;
while ((count = fis.read(buffer, 0, buffer.length)) > 0) {
toClient.write(buffer, 0, count);
}
toClient.flush();
} catch (Exception e) {
logger.error(e.getMessage(), e);
}finally {
if (toClient != null) {
try {
toClient.close();
} catch (IOException e) {
logger.warn(e.getMessage(), e);
}
}
if (fis != null) {
try {
fis.close();
} catch (IOException e) {
logger.warn(e.getMessage(), e);
}
}
}