private void riskNoticesExport(HttpServletRequest request,
HttpServletResponse response) {
String noticeIds = request.getParameter("noticeIds");
String types = request.getParameter("types");
String[] noticeIdArr = noticeIds.split(";");
String[] typeArr = types.split(";");
File file = getNoticeFileZip(response,noticeIdArr,typeArr);
try {
// 以流的形式下载文件。
InputStream fis = new BufferedInputStream(new FileInputStream(file.getPath()));
byte[] buffer = new byte[fis.available()];
fis.read(buffer);
fis.close();
// 清空response
response.reset();
OutputStream toClient = new BufferedOutputStream(response.getOutputStream());
response.setContentType("application/octet-stream");
String fileName="11.zip";
//如果输出的是中文名的文件,在此处就要用URLEncoder.encode方法进行处理
response.setHeader("Content-Disposition", "attachment;filename=" + new String(fileName.getBytes("GBK"),"iso8859_1"));
toClient.write(buffer);
toClient.flush();
toClient.close();
} catch (IOException ex) {
ex.printStackTrace();
}finally{
try {
File f = new File(file.getPath());
f.delete();
} catch (Exception e) {
e.printStackTrace();
}
}
}
private File getNoticeFileZip(HttpServletResponse response,String[] noticeIdArr, String[] typeArr) {
String tempFilePath=Application.datFileRootPath+File.separator +Application.weekRiskFilePath+File.separator;
String tempFilePath2 = tempFilePath+"a@@a"+File.separator;
File filewjj = new File(tempFilePath2);
if(!filewjj .exists()){
filewjj .mkdir();
}else{
delAllFile(tempFilePath2);
}
List files = getNoticeFiles(tempFilePath2,noticeIdArr,typeArr);
File file = new File(tempFilePath+"1@@.zip");
try {
if(file.exists()){
file.delete();
file = new File(tempFilePath+"1@@.zip");
}
if (!file.exists()){