当前位置:网站首页>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);
}
}
}
边栏推荐
- Atcoder regular contest 133 d.range XOR (digital dp+ classification discussion)
- Analysis of browser decoding process
- 火了 2 年的服务网格究竟给微服务带来了什么?(转载)
- Learn about service discovery in kubernetes
- C#遍历集合
- Modeling Semantics with Gated Graph Neural Networks for KBQA
- 带参数的微信小程序二维码生成
- 【sqoop】sqoop1.4.7 安装集成CDH5.13
- Verilog 每日一题(VL8 使用generate…for语句简化代码)
- 创建自定义分页控件
猜你喜欢

Verilog 每日一题(VL29 单端口RAM)

Verilog 每日一题(VL2 异步复位的串联T触发器--牛客网)

Problem solution of code heartstrings Junior Group (official competition) of Dalian University of Technology (Development Zone campus) in 2021

Microservice Architecture - service registry and service gateway (6.8) (Reprint)

Vscode界面介绍

QR code generation of wechat applet with parameters

The practice of the beego framework for goweb development: Section V project construction and user registration

How to protect image security during construction

Unity shader cartoon style rendering

Reasoning Over Semantic-Level Graph for Fact Checking
随机推荐
Verilog 每日一题(VL14 自动贩售机1--FSM常见题型)
Verilog 每日一题(VL2 异步复位的串联T触发器--牛客网)
Verilog daily question (vl14 vending machine 1 -- FSM common question types)
Verilog daily question (vl27 settable counter)
The 2021 ICPC ASIA Taipei Regional programming contest L. leadfoot (combinatorics /2-adic assignment function +kummer theorem)
Source code of voice live broadcast app
Visual Studio 2015 团队开发之Azure DevOps篇
Solve the problem of exclusive SQL Server database
Verilog daily question (vl29 single port RAM)
Selection and application of inductors in high speed circuits
Microservice Architecture - service registry and service gateway (6.8) (Reprint)
The practice of the beego framework of goweb development: Section II project initialization configuration
Cf/atc/lc topic score website
【atlas】atlas 编译报错整理(全)
一文了解 Kubernetes 中的服务发现
Introduction to vscade interface
Verilog 每日一题 (VL28 加减计数器)
Verilog 每日一题 (VL24 多bit MUX同步器 跨时域输出)
充分利用----英文
Algorithm learning: leetcode interview question 09. implement queue with two stacks