设计思路:
1.本地先创建一个zip文件
2.将批量下载的文件依次放入zip文件中
3.将zip文件返回给前端
//一、本地先生成zip文件
//要批量下载的文件id数组
String[] ids = new String[] {"1","2"}
byte[] buffer = new byte[1024];
//创建zip
String localZipFile = "D:/temp/test.zip" ;
if(!new File(localZipFile).exists()){
new File(localZipFile).mkdirs();
}
ZipOutputStream out = new ZipOutputStream(new FileOutputStream(localZipFile));
//依次获取批量下载的文件
for(int i =0; i<ids.length;i++){
//设置压缩包内的文件的字符编码,不然文件名可能变成乱码(用户为windows系统)
out.setEncoding("GBK");
//从数据库中获取文件的路径和文件名,并放入zip文件中
String fileId = ids[i];
Map<String,Object> map =exportManagerService.getFjInfo(fileId);
FileInputStream inStream = new FileInputStream(new File(map.get("path").toString()));
out.putNextEntry(new ZipEntry(map.get("name").toString()));
int len;
//读入需要下载的文件的内容,打包到zip文件
while ((len = inStream.read