我正在提取一个 zip 文件,问题是百分比计算超过 100%,几乎达到 111%。这是代码:
boolean UNZipFiles() {
byte[] buffer = new byte[4096];
int length;
float prev = -1; // to check if the percent changed and its worth updating the UI
int finalSize = 0;
float current = 0;
String zipFile = PATH + FileName;
FileInputStream fin = new FileInputStream(zipFile);
ZipInputStream zin = new ZipInputStream(fin);
finalSize = (int) new File(zipFile).length();
ZipEntry ze = null;
while ((ze = zin.getNextEntry()) != null) {
current += ze.getSize();
if (ze.isDirectory())
dirChecker(ze.getName());
else {
FileOutputStream fout = new FileOutputStream(PATH + ze.getName());
while ((length = zin.read(buffer)) > 0)
fout.write(buffer, 0, length);
if (prev != current / finalSize * 100) {
prev = current / finalSize * 100;
UpdatePercentNotificationBar((int) prev);
}
zin.closeEntry();
fout.close();
}
}
zin.close();
return true;
}
我怎样才能解决这个问题?