如何在Android应用程序的解压缩过程中使用确定的进度条?
我知道我需要处理文件以更新进度条,但不知道如何获取此信息。
谢谢!
P.S。我用来解压在这篇文章中找到的代码:https://stackoverflow.com/a/7697493/1364296
答案 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();
}
}
尝试在解压缩时使用缓冲区,因为它会更快