开发者

Java calculate progress on UnZipping process

I'm using an Unzipping process that I want to calculate its progress, here is the code with the counter:

float counter;
@Override
protected Boolean doInBackground(String... params) {
    try {

        String zipFile = Path + FileName;

        String unzipLocation = Path;

        FileInputStream fin = new FileInputStream(zipFile);
        ZipInputStream zin = new ZipInputStream(fin);

        ZipEntry ze = null;
        while ((ze = zin.getNextEntry()) != null) {
            counter++;
            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)开发者_StackOverflow社区;                  
                }
                publishProgress((int)((counter/747.0)*100));
                zin.closeEntry();
                fout.close();
            }

        }
        zin.close();
    } catch (Exception e) {
        mProgressDialog.dismiss();
        return false;
    }

    return true;
    }

  @Override
protected void onProgressUpdate(Integer... values) {
    mProgressDialog.setProgress(values[0]);
}

I have only 1 .zip file which contains exactly 747 files... that why I use the number 747.

The problem is that values[0] is always 0 .. Am I calculating the process right? How should I do this? Thanks.


Use the last published value from the progress:

mProgressDialog.setProgress(values[values.length - 1]);

Possible problems:

  • It might be that the progress of unzipping is so fast (or the GUI updating is slow) that values = [0, 1, .... 99]
  • Your progress dialog isn't set up correctly (setMax and setMin)
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜