下载压缩文件并打包

public String downloadjsglfj(){
String id = getServletRequest().getParameter("id");
String jsmc = getServletRequest().getParameter("jsmc");
List<FjxxbVO> list=fjxxService.getJsglFjByFId(id,"jsglfj");
if(list.size()>0){
try {
fileName= jsmc+".zip";
this.inputStream=SftpUtils.batchDownload(list);
} catch (Exception e) {
e.printStackTrace();
}
}else{
return null;
}


return SUCCESS;
}

--------------------------

public static InputStream batchDownload(List<FjxxbVO> list){
ByteArrayOutputStream bos=new ByteArrayOutputStream();
try{
sftp = connect(ftpServer, ftpPort, ftpAccount, ftpPassword);
ZipOutputStream out = new ZipOutputStream(bos);
byte[] buf = new byte[4096];
for (FjxxbVO fjxxbVO : list) {
InputStream in = null;
try {

in=sftp.get(fjxxbVO.getLj()+"/"+fjxxbVO.getSsmc());

out.putNextEntry(new ZipEntry(fjxxbVO.getOrgname()+"."+fjxxbVO.getWjlx()));

int len;
while ((len = in.read(buf)) > 0) {
out.write(buf, 0, len);
}
out.closeEntry();
in.close();


} catch (Exception e) {
e.printStackTrace();
}

}

//inputStream=sftp.get(fileDir);
out.close();
bos.close();

} catch (FileNotFoundException e) {
} catch (Exception e) {
e.printStackTrace();
}

return new ByteArrayInputStream(bos.toByteArray());

}

 

posted on 2017-07-14 09:21  王宏伟的博客  阅读(110)  评论(0编辑  收藏  举报