安卓:是否有可能添加ZIP文件作为原料资源,并的ZipFile看了吗?看了、有可能、原料、文件

2023-09-06 06:37:28 作者:现在就任它结疤

是否有可能ZIP文件添加到APK包作为原料资源,而对的ZipFile类看过吗?它看起来是微不足道的打开从SD卡的文件,而不是从APK。

Is it possible to add ZIP file to APK package as a raw resource and read it with ZipFile class? It looks like it's trivial to open file from SD card, but not from APK.

推荐答案

我不这么认为。至于你提到,它很容易使用的ZipFile 与文件系统上的实际文件,但不能因此对嵌入式应用程序中的一个文件。

I don't believe so. As you alluded, it's easy to use ZipFile with an actual file on the file system, but not so for a file embedded in your application.

有关在访问您的APK一个zip文件,你必须使用像 Resources.openRawResource(R.raw.zip_file) 然后包裹退回的InputStream ZipInputStream 并做到这一点通常的Java方法,而不是Android的方法。

For accessing a zip file in your APK, you'd have to use something like Resources.openRawResource(R.raw.zip_file) and then wrap the returned InputStream in a ZipInputStream and do it the usual Java way, rather than with the Android method.

另外,如果你真的觉得你需要使用的ZipFile 类,你可以从APK zip文件解压到SD卡,或者更可靠,你应用程序的本地存储。

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