Unable to extract obb file downloaded from google play application

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-09 23:47:48

问题


I implmeneted apk expansion successfully.And obb file downloaded at Android->Obb->PackageName->com.1.com.packagename.obb

But when i go to extract i am getting issue.Eof file exception in log Unzip exception2.

Exception:- java.io.FileNotFoundException: /storage/sdcard0/.MyApp/BGP050@2x.jpg: open failed: ENOENT (No such file or directory)

Please reply if anyone have idea thanks in advance....

Function From calling to extract file

public void extract()
{

            String packageName = getApplicationContext().getPackageName();

            File root = Environment.getExternalStorageDirectory();
            File expPath = new File(root.toString() + "/Android/obb/" + packageName);

            if (expPath.exists()) {
                String strMainPath = null;
                try {
                    strMainPath = expPath + File.separator + "main."
                        + getPackageManager().getPackageInfo(
                                    getPackageName(), 0).versionCode + "."
                            + packageName + ".obb";


                Log.e("Extract File path", "===>"+strMainPath);

                File f=new File(strMainPath);
                if(f.exists()){
                    Log.e("Extract From File path", "===> not exist");
                }
                else
                {
                    Log.e("Extract From File path", "===> exist");
                }

                flag = extractZip(strMainPath,Environment.getExternalStorageDirectory()+"/"+Constant.FOLDERNAME);

                Log.e("After Extract Zip", "===>"+flag);
                } catch (NameNotFoundException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }

            }

}

Function is below

private boolean extractZip(String pathOfZip,String pathToExtract)
 {


        int BUFFER_SIZE = 1024;
        int size;
        byte[] buffer = new byte[BUFFER_SIZE];


        try {
            File f = new File(pathToExtract);
            if(!f.isDirectory()) {
                f.mkdirs();
            }
            ZipInputStream zin = new ZipInputStream(new BufferedInputStream(new FileInputStream(pathOfZip), BUFFER_SIZE));
            try {
                ZipEntry ze = null;
                while ((ze = zin.getNextEntry()) != null) {
                    String path = pathToExtract  +"/"+ ze.getName();

                    if (ze.isDirectory()) {
                        File unzipFile = new File(path);
                        if(!unzipFile.isDirectory()) {
                            unzipFile.mkdirs();
                        }
                    }
                    else {
                        FileOutputStream out = new FileOutputStream(path, false);
                        BufferedOutputStream fout = new BufferedOutputStream(out, BUFFER_SIZE);
                        try {
                            while ( (size = zin.read(buffer, 0, BUFFER_SIZE)) != -1 ) {
                                fout.write(buffer, 0, size);
                            }

                            zin.closeEntry();
                        }catch (Exception e) {
                            Log.e("Exception", "Unzip exception 1:" + e.toString());
                        }
                        finally {
                            fout.flush();
                            fout.close();
                        }
                    }
                }
            }catch (Exception e) {
                Log.e("Exception", "Unzip exception2 :" + e.toString());
            }
            finally {
                zin.close();
            }
            return true;
        }
        catch (Exception e) {
            Log.e("Exception", "Unzip exception :" + e.toString());
        }
        return false;

    }

回答1:


Try this:-

After very struggle finally i found a solution.I was ziping the whole folder with subfolder also by right click in ubuntu12.04.

But After that i tried select all images/files then zip them to new folder. By the above code i was able to extracted all the files successfully.

Thanks......



来源:https://stackoverflow.com/questions/20217663/unable-to-extract-obb-file-downloaded-from-google-play-application

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!