java 如何将多个文件打包成一个zip后进行下载

java 如何将多个文件打包成一个zip后进行下载,第1张

打包压缩的如下:

ZipOutputStream out=new ZipOutputStream(new FileOutputStream(zipFileName))

for(int i=0i<逗稿握fileList.size()i++){

String filename = (String)fileList.get(i)

File file = new File(filename)

zip(out,file)

}

out.close()

下载的如下:

private int blockSize=65000

File file = new File(sourceFilePathName)

FileInputStream fileIn = new FileInputStream(file)

int readBytes = 0

readBytes = fileIn.read(b, 0, blockSize)

totalRead += readBytes

out.write(b, 0, readBytes)

代码大致敬派如此,请参考。山庆

java从html页面下载zip文件方法,当 Chrome/Edge 开始下载文雀携件时,它们会将其视为 html 文件而不是 zip。

将下载的 .html 重命名为敏岁游 .zip 然后给出正确的文件,所以我正确地创建了 zip。

如果我将 Edge 设桥销置为提示下载,而不是自动下载文件,那么我可以在下载时将其视为 zip 文件。


欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/tougao/12249130.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-05-22
下一篇 2023-05-22

发表评论

登录后才能评论

评论列表(0条)

保存