当前位置:网站首页>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);
}
}
}
边栏推荐
- 线性代数及矩阵论(八)
- LNMP源码编译安装
- Code implementation additive attention
- Source code of voice live broadcast app
- Unity shader global fog effect
- Verilog 每日一题(VL6 数据串转并电路)
- 2021年4月份自考
- QR code generation of wechat applet with parameters
- Algorithm learning: leetcode interview question 09. implement queue with two stacks
- WPF command button transparent style
猜你喜欢

High speed circuit design practice -- Overview

高速电路中电容的选型和应用——详解

Classroom attendance system based on QT design (using RDS for MySQL cloud database)

Verilog daily question (vl29 single port RAM)

UNIQUE VISION Programming Contest 2022(AtCoder Beginner Contest 248)G. GCD cost on the tree

Introduction to vscade interface

Verilog daily question (vl28 plus and minus counter)

Gray code and binary conversion and typical examples (4bits gray code counter)

Selection and application of capacitor in high speed circuit -- detailed explanation

Goweb开发之Beego框架实战:第四节 数据库配置及连接
随机推荐
一文了解 Kubernetes 中的服务发现
Asynchronous circuit design -- principle and example of synchronous pulser
Andthen of function interface
Verilog daily question (vl8 uses generate... For statement to simplify code)
数据库故障容错之系统时钟故障
Message Passing for Complex Question Answering over Knowledge Graphs
充分利用----英文
【kibana】问题整理 kibana 7.x No indices match pattern “apm-*“
在android开发过程中遇到.sqlite文件处理
High speed circuit design practice -- Overview
微服务架构-服务注册中心和服务网关(6.8) (转载)
Microservice Architecture - service registry and service gateway (6.8) (Reprint)
Function接口之andThen
QR code generation of wechat applet with parameters
WPF command button transparent style
Goweb开发之Beego框架实战:第二节 项目初始化配置
Analysis of browser decoding process
Why do I choose to use go language?
Unity shader realizes water wave effect with noise texture
wpf命令按钮透明样式