0

I do not want the overhead of copying so many files from android assets directory to my app's internal storage. That is why I have created a zip file in assets folder and I will copy that zip file on my android app's internal storage. After copying it, I will extract/unzip it on the same location and after extraction is complete I will delete this zip file.

The idea is to remove the overhead of copying so many files. Also while copying so many files I am getting IOException with some file types. Which again was a hinderance. That is why I am trying to do so as I have discussed above. But the problem is that how can I extract a zip file that is residing in my app's internal storage. I want to extract it on the same location(App's internal storage). How can I achieve this?

I have also checked this code but inside unzip() method my code never goes inside while loop. Unzip File in Android Assets

public void unzip() {
        try {
            FileInputStream fin = new FileInputStream(_zipFile);
            ZipInputStream zin = new ZipInputStream(fin);
            ZipEntry ze = null;
            while ((ze = zin.getNextEntry()) != null) {
                Log.v("Decompress", "Unzipping " + ze.getName());

                if (ze.isDirectory()) {
                    _dirChecker(ze.getName());
                } else {
                    FileOutputStream fout = new FileOutputStream(_location
                            + ze.getName());
                    for (int c = zin.read(); c != -1; c = zin.read()) {
                        fout.write(c);
                    }

                    zin.closeEntry();
                    fout.close();
                }

            }
            zin.close();
        } catch (Exception e) {
            Log.e("Decompress", "unzip", e);
        }

    }

This is the unzip code. But I am never getting inside the while loop

while ((ze = zin.getNextEntry()) != null) {
                    Log.v("Decompress", "Unzipping " + ze.getName());

                    if (ze.isDirectory()) {
                        _dirChecker(ze.getName());
                    } else {
                        FileOutputStream fout = new FileOutputStream(_location
                                + ze.getName());
                        for (int c = zin.read(); c != -1; c = zin.read()) {
                            fout.write(c);
                        }

                        zin.closeEntry();
                        fout.close();
                    }

                }

What might be the reason if I use this code. Or if you guys help me out with some other code and help then it is appreciated.

Community
  • 1
  • 1
Master
  • 2,945
  • 5
  • 34
  • 65
  • Have you tried something, done any research? How about this: http://stackoverflow.com/questions/11614949/reading-files-from-a-zip-file-in-your-android-assets-folder?rq=1 – marcinj Jan 12 '14 at 08:22
  • I did. But most of the times I found the ways to copy files from assets folder to sdcard. Unizipping is still a problem for me. I am taking a look at your suggested link. – Master Jan 12 '14 at 08:40
  • I am able to copy zip file from assets folder to sdcard but now I want to unzip it at the same location, that is what I need to do now. – Master Jan 12 '14 at 08:41

0 Answers0