如何在Android中更新ProgressBar for UnZip File

时间:2012-04-29 15:18:14

标签: java android progress-bar unzip

如何在Android应用程序的解压缩过程中使用确定的进度条?

我知道我需要处理文件以更新进度条,但不知道如何获取此信息。

谢谢!

P.S。我用来解压在这篇文章中找到的代码:https://stackoverflow.com/a/7697493/1364296

2 个答案:

答案 0 :(得分:3)

  

如何在Android应用程序的解压缩过程中使用确定的进度条?

使用ZipFile查找条目数。在setMax()上使用ProgressBar来设置上限进度。然后,在处理每个文件时,将进度增加1。

答案 1 :(得分:1)

邮政编码的

使用此。

public static void zip(String[] files, String zipFile) throws IOException {
    BufferedInputStream origin = null;
    ZipOutputStream out = new ZipOutputStream(new BufferedOutputStream(new FileOutputStream(zipFile)));
    try { 
        byte data[] = new byte[BUFFER_SIZE];

        for (int i = 0; i < files.length; i++) {
            FileInputStream fi = new FileInputStream(files[i]);    
            origin = new BufferedInputStream(fi, BUFFER_SIZE);
            try {
                ZipEntry entry = new ZipEntry(files[i].substring(files[i].lastIndexOf("/") + 1));
                out.putNextEntry(entry);
                int count;
                while ((count = origin.read(data, 0, BUFFER_SIZE)) != -1) {
                    out.write(data, 0, count);
                }
            }
            finally {
                origin.close();
            }
        }
    }
    finally {
        out.close();
    }
}

尝试在解压缩时使用缓冲区,因为它会更快

相关问题