当前位置:网站首页>批量下载文件
批量下载文件
2022-07-28 16:19: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));
//设置压缩方法
zipOs.setMethod(ZipOutputStream.DEFLATED);
//遍历文件信息(主要获取文件名/文件路径等)
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();
//文件名(包含后缀名,如:测试.pdf)
String name = t;
log.info("batchDownloadFile:[fileName:{}]", name);
//添加ZipEntry,并将ZipEntry中写入文件流
zipOs.putNextEntry(new ZipEntry(name));
//读入需要下载的文件的内容,打包到zip文件
os = new DataOutputStream(zipOs);
os.write(data);
//关闭流
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("流关闭异常{}", e);
}
}
}
边栏推荐
- The longest substring of sword finger offer without repeated characters
- 做题笔记4(第一个错误的版本,搜索插入位置)
- How should I understand craft
- Semtech推出物联网地理定位解决方案LoRa Edge,首款芯片LR1110现已上市
- HTAP comes at a price
- Comprehensively design an oppe homepage -- after sales service of the page
- Reduce cycle complexity
- go语言慢速入门——流程控制语句
- PostgreSQL weekly news - July 20, 2022
- Alibaba cloud MSE supports go language traffic protection
猜你喜欢

kubernetes service 原理解析

Comprehensively design an oppe homepage -- after sales service of the page

Realization of reflection and refraction effect in unity shader cube texture
![[deep learning]: model evaluation and selection on the seventh day of pytorch introduction to project practice (Part 1): under fitting and over fitting (including source code)](/img/19/18d6e94a1e0fa4a75b66cf8cd99595.png)
[deep learning]: model evaluation and selection on the seventh day of pytorch introduction to project practice (Part 1): under fitting and over fitting (including source code)

Outline and principle of structured design -- modularization
![[deep learning]: the second day of pytorch introduction to project practice: realize linear regression from zero (including detailed code)](/img/19/18d6e94a1e0fa4a75b66cf8cd99595.png)
[deep learning]: the second day of pytorch introduction to project practice: realize linear regression from zero (including detailed code)

概率论与数理统计第一章

Re13: read the paper gender and racial stereotype detection in legal opinion word embeddings

浏览器解码过程分析

综合设计一个OPPE主页--页面服务部分
随机推荐
Time complexity
Easypoi --- excel file export
2020Q2全球平板市场出货大涨26.1%:华为排名第三,联想增幅最大!
做题笔记5(有序数组的平方)
Some opinions on bug handling
综合设计一个OPPE主页--页面服务部分
深入理解 DeepSea 和 Salt 部署工具 – Storage6
Exercise note 5 (square of ordered array)
parseJson
全链路灰度在数据库上我们是怎么做的?
: No such file or directory
Re10: are we really making much progress? Revisiting, benchmarking, and refining heterogeneous gr
mysql 最大建议行数2000w,靠谱吗?
Realize the reset function of steering wheel UI with touch rotation and finger departure in unity
总数据量超万亿行,玉溪卷烟厂通过正确选择时序数据库轻松应对
Unity shader transparent effect
Games101-assignment05 ray tracing - rays intersect triangles
【深度学习】:《PyTorch入门到项目实战》第一天:数据操作和自动求导
Ugui learning notes (VI) get the information of the clicked UI
【深度学习】:《PyTorch入门到项目实战》第二天:从零实现线性回归(含详细代码)