1

I have a problem.

I use this code to read the content of a zip file:

    File file = new File(TogglesManager.EXTERNAL_STORAGE_THEMES_DIRECTORY+"filename.zip");
    ZipFile zip = new ZipFile(file);

But when I try to use an assets I have a FileNotFoundException.

To read asset zip file I use this code:

    File file = c.getFileStreamPath("assetsFile.zip");
    ZipFile zip = new ZipFile(file);

The "file" is not null, because if I write file.getName(); I see the correct file name.

I don't want to use ZipInputStream class, but only ZipFile

rsp
  • 23,135
  • 6
  • 55
  • 69
Meroelyth
  • 5,310
  • 9
  • 42
  • 52

1 Answers1

3

You cannot access Assets using normal file operations. You will have to use

AssetManager assetManager = mContext.getAssets();
InputStream is = assetManager.open("assetsFile.zip");

But since ZipFile does not take InputStream as a parameter, you will have to copy asset file onto internal storage and then use File

Further AFAIK, apk is zipped, so storing a zipped file inside assets might not change storage used by much, so maybe you donot need to use zipfile inside assets.

nandeesh
  • 24,740
  • 6
  • 69
  • 79
  • Many thanks..there is another way instead of ZipFile or ZipInputStream to read Zip file without extract it? – Meroelyth Nov 19 '12 at 19:36
  • I am not too sure, but ZipInputStream should do the job using InputStream that you have got from assetManager.open – nandeesh Nov 19 '12 at 19:38
  • 1
    `Further AFAIK, apk is zipped, so storing a zipped file inside assets might not change storage used by much, so maybe you donot need to use zipfile inside assets.` Confirmed & Thanks – Muhammad Babar Feb 02 '15 at 09:57
  • can you confirm the validity of the statement @MuhammadBabar – Shubham AgaRwal Oct 03 '19 at 07:27
  • 1
    @Killer as APK is itself zipped so bundled files will automatically be zipped. But Sorry as the thread is quite old so I can't confirm the validity. BTW you can verify it yourself by adding files both zipped and unzipped and check the size. – Muhammad Babar Oct 07 '19 at 09:23