这是我的代码:
public void extract(String input_f, String output_f){
int buffersize = 1024;
FileInputStream in;
try {
in = new FileInputStream(input_f);
FileOutputStream out = new FileOutputStream(output_f);
BZip2CompressorInputStream bzIn = new BZip2CompressorInputStream(in);
final byte[] buffer = new byte[buffersize];
int n = 0;
while (-1 != (n = bzIn.read(buffer))) {
out.write(buffer, 0, n);
}
out.close();
bzIn.close();
} catch (Exception e) {
throw new Error(e.getMessage());
}
}
如何在解压任务中添加进度条,或者如何获取压缩文件的大小?
最佳答案
最好的方法是:
向您的方法/类添加回调或监听器(我更喜欢监听器列表以提供更大的灵 active )。
计算压缩文件大小(S)。
将读取的总字节数保留到时刻(B)。
对于每次迭代,向 B/S 的回调/监听器报告。让监听器决定如何处理该数据。
关于java - 将进度条添加到 BZip2CompressorInputStream,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9963965/