I'd like to use the ZipFile
class to unzip a file using its name from an archive of multiple files. How can I get the string of the zip file name and directory to pass to the ZipFile
constructor?
Asked
Active
Viewed 8,572 times
4

CalvinS
- 615
- 1
- 7
- 14
-
What is the path name if the zip file is in the assets directory? Is my best choice to copy it to the application files directory? – CalvinS Jun 04 '10 at 14:33
-
An APK is already a compressed ZIP archive. Putting a ZIP inside of an APK is a waste of time -- just put the APK's contents in there. – CommonsWare Jun 04 '10 at 16:04
1 Answers
4
You can use the AssetManager and ZipInputStream http://developer.android.com/reference/android/content/res/AssetManager.html
ZipInputStream in = null;
try {
final String zipPath = "data/sample.zip";
// Context.getAssets()
in = new ZipInputStream(getAssets().open(zipPath));
for (ZipEntry entry = in.getNextEntry(); entry != null; entry = in.getNextEntry()) {
// handle the zip entry
}
} catch (IOException e) {
Log.e(TAG, e.getMessage());
} finally {
try {
if (in != null) {
in.close();
}
} catch (IOException ignored) {
}
in = null;
}

qrtt1
- 7,746
- 8
- 42
- 62