当前位置:网站首页>Batch download files
Batch download files
2022-07-28 17:25:00 【DC_ Zhang】
public static void main(String[] args) throws IOException {
DataOutputStream os = null;
ZipOutputStream zipOs = null;
List<String> fileUrls = Arrays.asList("D:\\test\\test1.txt", "D:\\test\\\\test.txt");
try {
File outFile = new File("D:\\test\\zzz.zip");
FileOutputStream fos = new FileOutputStream(outFile);
zipOs = new ZipOutputStream(new BufferedOutputStream(fos));
// Set compression method
zipOs.setMethod(ZipOutputStream.DEFLATED);
// Traverse file information ( Mainly get the file name / File path, etc )
for (String t : fileUrls) {
File file = new File(t);
FileInputStream fis = null;
ByteArrayOutputStream bos = new ByteArrayOutputStream(1000);
fis = new FileInputStream(file);
byte[] b = new byte[1000];
int n;
while ((n = fis.read(b)) != -1) {
bos.write(b, 0, n);
}
byte[] data = bos.toByteArray();
// file name ( Contains the suffix , Such as : test .pdf)
String name = t;
log.info("batchDownloadFile:[fileName:{}]", name);
// add to ZipEntry, And will ZipEntry Write file stream to
zipOs.putNextEntry(new ZipEntry(name));
// Read in the content of the file you need to download , Pack to zip file
os = new DataOutputStream(zipOs);
os.write(data);
// Closed flow
zipOs.closeEntry();
}
outFile.createNewFile();
} catch (Exception e) {
} finally {
try {
if (os != null) {
os.flush();
os.close();
}
if (zipOs != null) {
zipOs.close();
}
} catch (IOException e) {
log.error(" Flow closing exception {}", e);
}
}
}
边栏推荐
- Goweb开发之Beego框架实战:第四节 数据库配置及连接
- Goweb开发之Iris框架实战:项目总结与回顾
- Azure Devops developed by visual studio 2015 team
- Solve the problem of exclusive SQL Server database
- The practice of the beego framework of goweb development: Section II project initialization configuration
- 数据库故障容错之系统时钟故障
- The actual combat of the beego framework of goweb development: Section III program execution process analysis
- 【impala】【报错解决】 Impala cannot read or execute the parent directory of dfs.domain.socket.path的解决方法
- Kubernetes service and ingress you need to master
- C# 导入Excel文件数据的几种方法
猜你喜欢

火了 2 年的服务网格究竟给微服务带来了什么?(转载)

Basic principle of asynchronous FIFO (simple implementation based on Verilog)

C# 导入Excel文件数据的几种方法

Reasoning Over Semantic-Level Graph for Fact Checking

高速电路设计实践——概述

wpf命令按钮透明样式

Use Alibaba cloud's free SSL certificate

MySQL数据库增删改查(基础操作命令详解)

mysql 最大建议行数2000w,靠谱吗?

Jupyter notebook win installation record
随机推荐
net框架
Goweb开发之Beego框架实战:第五节 项目搭建及注册用户
堡垒机的作用
Difference between reconnaissance aircraft and early warning aircraft
The practice of beego framework in goweb development: Section I Introduction to beego framework
Goweb开发之Beego框架实战:第四节 数据库配置及连接
Shopee code League 2022 - qualification round p3.connecting the numbers (segment tree / bipartite graph determination, to be discussed)
Goweb开发之Iris框架实战:项目总结与回顾
Goweb开发之Beego框架实战:第三节 程序执行流程分析
Selection and application of inductors in high speed circuits
Verilog 每日一题 (VL28 加减计数器)
全链路灰度在数据库上我们是怎么做的?
UNIQUE VISION Programming Contest 2022(AtCoder Beginner Contest 248)G. GCD cost on the tree
Goweb开发之Beego框架实战:第四节 数据库配置及连接
总数据量超万亿行,玉溪卷烟厂通过正确选择时序数据库轻松应对
Role of Fortress machine
The practice of the beego framework of goweb development: Section II project initialization configuration
异步FIFO基本原理(基于Verilog的简单实现)
Leetcode 2022.04.10 China Merchants Bank special competition D. store promotion (DP)
C# 导入Excel文件数据的几种方法