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.文章转载时请保留本站内容来源地址,https://www.lu-xu.com/keji/3278464.html