zip压缩下载
Action
/**
* 压压压下
* @author 李蒙
* @return
* @throws Exception
*/
public String bathdownloadAttachment() throws Exception {
//压压压压压压压压压压压下名字中文乱
strZipName=new String("压压压压压意度自述告.zip".getBytes("GBK"), "ISO-8859-1");
inputStream=batchDownloadAttchService.bathdownloadAttachment(selfReportsIds);
return "bathdownloadAttachment";
}
Service
/**
* @功能:附件压压压压
* @author 李蒙
* @return
* @throws Exception
*/
public InputStream bathdownloadAttachment(List
selfReportsIds) throws Exception {
byte[] buffer = new byte[8094];
//压压压压压压压压压压压压压压置写入服器名字加上戳区分附件
String writeName = System.currentTimeMillis()+".zip";
//压压附件
List f=this.findTpmsReSelfReports(selfReportsIds);
//服起路径压压压压
String
saveRootPath=ServletActionContext.getRequest().getSession().getServletContext().getRealPath(File.separator);
//生成附件的路径
String fileRelativePath =
saveRootPath+File.separator+"reportsUploads"+File.separator+writeName;
//在fileRelativePath生成文件
File file = new File(fileRelativePath);
if(f.size()!=0&&f!=null){
//写入文件
ZipOutputStream outInputStream = new
ZipOutputStream(new FileOutputStream(fileRelativePath));
for (int i = 0; i < f.size(); i++) {
fileInputStream = new
FileInputStream(f.get(i));
outInputStream.putNextEntry(new ZipEntry(f.get(i).getName()));
int len;
// 压压压压压压压压压压压压入需要下的文件的内容,打包到zip 文件
while ((len = fileInputStream.read(buffer)) > 0) {
outInputStream.write(buffer, 0, len);
}
outInputStream.closeEntry();
fileInputStream.close();
}
inputStream = new FileInputStream(file);
outInputStream.close();
return inputStream;
}
return null;
}
Struts
application/octet-stream;charset=ISO8859-1
inputStream
attachment;filename="${strZipName}"
8094