首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在Android上'On the fly‘解压文件

在Android上'On the fly‘解压文件
EN

Stack Overflow用户
提问于 2014-07-29 20:43:18
回答 1查看 56关注 0票数 0

我需要打包几个文件(总大小达4 GB ),这将在网上可用。android应用程序需要在不将存档文件保存到设备上的情况下‘即时’下载。因此,基本上设备不会保存存档,然后解包,因为这将需要两倍的空间。我应该选择哪种支持它的软件包格式(例如,zip、tar.gz等)?

EN

回答 1

Stack Overflow用户

发布于 2014-07-29 20:49:50

使用.zip!您可以使用ZipInputStreamZipOutputStream动态读取和写入.zip文件。不需要从归档文件中提取文件。

下面是一个简单的例子:

代码语言:javascript
复制
InputStream is =...
ZipInputStream zis = new ZipInputStream(new BufferedInputStream(is));
try {

    // ZipEntry contains data about files and folders in the archive.
    ZipEntry ze; 

    // This loops through the whole content of the archive
    while ((ze = zis.getNextEntry()) != null) {

        // Here we read the whole data of one ZipEntry
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        byte[] buffer = new byte[1024];
        int count;
        while ((count = zis.read(buffer)) != -1) {
            baos.write(buffer, 0, count);
        }

        // The ZipEntry contains data about the file, like its filename
        String filename = ze.getName();

        // And that's the file itself as byte array
        byte[] bytes = baos.toByteArray();

        // Do something with the file            
    }
} finally {
    zis.close();
}
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/25015621

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档