实际上,我尝试使用zipOutputStream压缩文件,但是每次都无法正确压缩文件时。它卡在更大尺寸的特定文件中。 我的代码如下所示:
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);
}
}
输出如下:
bytes read = 163840
Total bytes = 163840
bytes read = 163840
Total bytes = 327680
bytes read = 7940
Total Bytes = 335620
不知何故,它无法读取。文件大小为336 KB。 因此,我相信读取的总字节数是文件大小。但是,当尝试打开zip文件时,出现一些错误,提取的文件不完整。从zip中提取的内容只有2468行,而原始文件则超过3500行。
请帮助。我被困在最近4天了。