我需要打包几个文件(总大小达4 GB ),这将在网上可用。android应用程序需要在不将存档文件保存到设备上的情况下‘即时’下载。因此,基本上设备不会保存存档,然后解包,因为这将需要两倍的空间。我应该选择哪种支持它的软件包格式(例如,zip、tar.gz等)?
发布于 2014-07-29 20:49:50
使用.zip!您可以使用ZipInputStream和ZipOutputStream动态读取和写入.zip文件。不需要从归档文件中提取文件。
下面是一个简单的例子:
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();
}https://stackoverflow.com/questions/25015621
复制相似问题