Actually I was trying to zip files using zipOutputStream but everytime it is not able to zip files properly. It gets stuck at a particular file of bigger size. My code looks like below:
byte[] buf = new byte[1600*1024];
long totalBytes = 0;
if(flag){
FileInputStream fileStream = new FileInputStream(absoluteFileName);
zip.putNextEntry(new ZipEntry(fileName));
while ((len = fileStream.read(buf)) > 0) {
System.out.println("bytes read = "+len);
totalBytes += len;
System.out.println("totalBytes = "+totalBytes);
zip.write(buf, 0, len);
}
}
The output looks like below:
bytes read = 163840
Total bytes = 163840
bytes read = 163840
Total bytes = 327680
bytes read = 7940
Total Bytes = 335620
Somehow it is not able to read beyond that. The file size is 336 KB. So, I believe the total bytes read is file size. But when trying to open the zip file , I get some error and the file extracted is not complete. The one extracted from zip is only 2468 lines while the original file is more than 3500 lines.
Please help. I am stuck in this for last 4 days.