当前位置:网站首页>批量下载文件
批量下载文件
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);
}
}
}
边栏推荐
- Codeforces round 768 (Div. 2) e.paint the middle (greedy / interval relationship processing)
- List of supplementary questions
- 华为Mate 40系列曝光:大曲率双曲面屏,5nm麒麟1020处理器!还将有天玑1000+的版本
- 微服务架构-服务注册中心和服务网关(6.8) (转载)
- Unity shader uses rendered texture to achieve glass effect
- SUSE Ceph 增加节点、减少节点、 删除OSD磁盘等操作 – Storage6
- Round 1A 2022 - Code jam 2022 c.weightlifting (interval DP)
- Huawei mate 40 series exposure: large curvature hyperboloid screen, 5nm kylin 1020 processor! There will also be a version of Tianji 1000+
- Add differential pairs and connections in Ad
- Reduce cycle complexity
猜你喜欢

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

ERROR: transport library not found: dt_ socket

MySQL安装教程

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

负整数及浮点数的二进制表示

HTAP是有代价的
![[deep learning]: day 5 of pytorch introduction to project practice: realize softmax regression from 0 to 1 (including source code)](/img/19/18d6e94a1e0fa4a75b66cf8cd99595.png)
[deep learning]: day 5 of pytorch introduction to project practice: realize softmax regression from 0 to 1 (including source code)

Re12: read these3 semantic self segmentation for abstract summary of long legal documents in low

Jsonarray traversal

MySQL installation tutorial
随机推荐
Binary representation of negative integers and floating point numbers
Make full use of English
负整数及浮点数的二进制表示
Re10: are we really making much progress? Revisiting, benchmarking, and refining heterogeneous gr
Re12:读论文 Se3 Semantic Self-segmentation for Abstractive Summarization of Long Legal Documents in Low
Ugui learning notes (II) Scrollview related
Reduce cycle complexity
Ugui learning notes (I) rendering level
In 2020q2, shipments in the global tablet market soared by 26.1%: Huawei ranked third and Lenovo increased the most!
做题笔记4(第一个错误的版本,搜索插入位置)
Unity editor learning (I) using features to change the display of fields in components
Ugui learning notes (IV) ugui event system overview and Usage Summary
Algorithm learning: leetcode interview question 09. implement queue with two stacks
Analysis of browser decoding process
Comprehensively design an oppe homepage -- page service part
Codeforces round 770 (Div. 2) e. fair share
Semtech launched Lora edge, a geolocation solution for the Internet of things, and the first chip lr1110 is now on the market
做题笔记3(二分查找)
Easypoi --- excel file export
Codeforces Round #750 (Div. 2) F.Korney Korneevich and XOR (easy&&hard version)(dp)