如何创建多个图像文件的zip文件 [英] How to create a zip file of multiple image files
本文介绍了如何创建多个图像文件的zip文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试创建多个图像文件的zip文件。我已成功创建所有图像的zip文件,但不知何故所有图像都被挂起到950字节。我不知道这里出了什么问题,现在我无法打开将图像压缩成该zip文件。
I am trying to create a zip file of multiple image files. I have succeeded in creating the zip file of all the images but somehow all the images have been hanged to 950 bytes. I don't know whats going wrong here and now I can't open the images were compressed into that zip file.
这是我的代码。谁能让我知道这里发生了什么?
Here is my code. Can anyone let me know what's going here?
String path="c:\\windows\\twain32";
File f=new File(path);
f.mkdir();
File x=new File("e:\\test");
x.mkdir();
byte []b;
String zipFile="e:\\test\\test.zip";
FileOutputStream fout=new FileOutputStream(zipFile);
ZipOutputStream zout=new ZipOutputStream(new BufferedOutputStream(fout));
File []s=f.listFiles();
for(int i=0;i<s.length;i++)
{
b=new byte[(int)s[i].length()];
FileInputStream fin=new FileInputStream(s[i]);
zout.putNextEntry(new ZipEntry(s[i].getName()));
int length;
while((length=fin.read())>0)
{
zout.write(b,0,length);
}
zout.closeEntry();
fin.close();
}
zout.close();
推荐答案
更改此信息:
while((length=fin.read())>0)
到此:
while((length=fin.read(b, 0, 1024))>0)
并将缓冲区大小设置为1024字节:
And set buffer size to 1024 bytes:
b=new byte[1024];
这篇关于如何创建多个图像文件的zip文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文