当前位置:网站首页>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);
}
}
}
边栏推荐
猜你喜欢

Introduction to vscade interface

DGL Chapter 1 (official tutorial) personal notes

Atcoder regular contest 133 d.range XOR (digital dp+ classification discussion)

总数据量超万亿行,玉溪卷烟厂通过正确选择时序数据库轻松应对

格雷码和二进制的转换及典型例题(4bits格雷码计数器)

Source code of voice live broadcast app

Verilog 每日一题 (VL5 信号发生器)

Unity shader transparent effect

High speed circuit design practice -- Overview

How do we do full link grayscale on the database?
随机推荐
MySQL数据库增删改查(基础操作命令详解)
【CDH】通过 ClouderaManager 配置CDH组件用 prometheus 监控采集JMX信息
异步FIFO基本原理(基于Verilog的简单实现)
Visual Studio 2015 团队开发之Azure DevOps篇
Introduction to vscade interface
Verilog daily question (vl24 multi bit MUX synchronizer cross time domain output)
Goweb开发之Beego框架实战:第三节 程序执行流程分析
线性代数及矩阵论(八)
Andthen of function interface
Visual Studio 2012/2015发布Web应用连同.cs源码一起发布
Microservice Architecture - service registry and service gateway (6.8) (Reprint)
2021年4月份自考
一文了解 Kubernetes 中的服务发现
Cf/atc/lc topic score website
线性代数及矩阵论(九)
Some attention code explanations
The practice of beego framework in goweb development: Section I Introduction to beego framework
Role of Fortress machine
配置V530交换机步骤
Code implementation additive attention