java - How to create a zip file of multiple image files -
i trying create zip file of multiple image files. have succeeded in creating zip file of images somehow images have been hanged 950 bytes. don't know whats going wrong here , can't open images compressed zip file.
here code. can 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();
change this:
while((length=fin.read())>0)
to this:
while((length=fin.read(b, 0, 1024))>0)
and set buffer size 1024 bytes:
b=new byte[1024];
Comments
Post a Comment