gpt4 book ai didi

java - Zipentry 不是在 Android 中按顺序流式传输文件吗?

转载 作者:行者123 更新时间:2023-12-02 00:38:09 26 4
gpt4 key购买 nike

我正在尝试使用 android 中的 ZipEntry 类从 zip 文件中流式传输文件,但是我没有按字母顺序获取文件。

这是我的代码:

InputStream is = context.getResources().openRawResource(R.raw.file);
ZipInputStream zis = new ZipInputStream(new BufferedInputStream(is));
try {
ZipEntry ze;
while ((ze = zis.getNextEntry()) != null) {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
byte[] buffer = new byte[1024];
int count;
while ((count = zis.read(buffer)) != -1) {
baos.write(buffer, 0, count);
}
String filename = ze.getName();
byte[] bytes = baos.toByteArray();
int value = progress++;
task.doProgress(value);
Log.e(" -- zip process ---", "Filename: " + filename.toString());
// do something with 'filename' and 'bytes'...
}
} catch (IOException e) {
// TODO Auto-generated catch block
Log.e("Database Install", "Error: " + e.toString());
e.printStackTrace();
} finally {
try {
zis.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}

我不确定代码有什么问题。

最佳答案

ZipInputStream 按顺序读取条目,因此它们通常不能按字母顺序排列。如果您希望它们按字母顺序排列,您应该首先使用 ZipFile.entries() 阅读它们,根据需要排序并使用 ZipFile.getEntry() 访问条目。

关于java - Zipentry 不是在 Android 中按顺序流式传输文件吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7207244/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com