您的位置 首页 > 数码极客

如何将多个文件夹打包下载

package com.;

import java.io.file;

import java.io.FileInputStream;

import java.io.IOException;

import java.net.URLEncoder;

import java.u;

import java.u;

import java.u;

import javax.;

import javax.;

import org.a;

import org.a;

import org.;

import org.Factory;


public class DownloadUtil {

private static Logger logger = LoggerFac);

/**

* 页面传压缩的多个文件

* @param pdfs 文件列表

* @param response

* @throws IOException

*/

public static void exportZIP(List<File> pdfs, String zipFileName, HttpServletResponse response) throws IOException {

if(null == pdfs || 0 == ())

return;

ServletOutputStream os = null;

ZipOutputStream zipOS = null;

try {

os = getOutputStream(zipFileName, response);

zipOS = new ZipOutputStream(os);

for (File file : pdfs) {// 将pdf文件发送到客户端

ZipEntry entry = new ZipEntry());

zi(entry);

try(FileInputStream fis = new FileInputStream(file)){

IOU(fis, zipOS);

}

}

zi();

} catch (Exception e) {

logger.error(), e);

} finally {

if (null != zipOS)

zi();

if (null != os)

os.close();

}

}

/**

* 打开response输出流

* @param string

* @param response

* @return

* @throws IOException

*/

public static ServletOutputStream getOutputStream(String fileName, HttpServletResponse response) throws IOException {

re("Content-Disposition",

S("attachment;filename=", URLEncoder.encode(fileName, "UTF-8")));

re("Connection", "close");

re("Content-Type", "application/octet-stream");

return re();

}

}

责任编辑: 鲁达

1.内容基于多重复合算法人工智能语言模型创作,旨在以深度学习研究为目的传播信息知识,内容观点与本网站无关,反馈举报请
2.仅供读者参考,本网站未对该内容进行证实,对其原创性、真实性、完整性、及时性不作任何保证;
3.本站属于非营利性站点无毒无广告,请读者放心使用!

“如何将多个文件夹打包下载,如何将多个视频压缩到一个文件夹中”边界阅读