Android: is it possible to add a ZIP file as a source resource and read it using a ZipFile?

Can I add a ZIP file to the APK package as a raw resource and read it using the ZipFile class? It seems trivial to open the file from the SD card, but not from the APK.

+4
source share
1 answer

I don’t believe that. As you mentioned, it is easy to use ZipFile with the actual file in the file system, but not so for the file embedded in your application.

To access the zip file in the APK, you will need to use something like Resources.openRawResource(R.raw.zip_file) , and then wrap the returned InputStream in a ZipInputStream and do it in the usual Java way, rather than using the Android method.

Alternatively, if you really need to use the ZipFile class, you can extract the zip file from the APK to the SD card or, more reliably, to the local storage of your application.

+5
source

All Articles