I am trying to create a zip file from multiple image files. I managed to create a zip file of all the images, but somehow all the images were hung up to 950 bytes. I donβt know what is happening here, and now I canβt open the images that were compressed into this zip file.
Here is my code. Can someone tell me what is going on 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();
java file zip fileinputstream zipoutputstream
Vighanesh gursale
source share