无法提取从Google Play应用程序下载的obb文件

时间:2013-11-26 12:54:06

标签: android zip extract expansion

我成功实现了apk扩展。在Android下载了obb文件 - > Obb-> PackageName-> com.1.com.packagename.obb

但是,当我去提取我正在获得iss​​ue.Eof文件异常 在日志中解压缩例外2。

例外: - java.io.FileNotFoundException:/storage/sdcard0/.MyApp/BGP050@2x.jpg:open failed:ENOENT(没有这样的文件或目录)

如果有人提前感谢,请回复....

功能从调用提取文件

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();
                }

            }

}

功能在

之下
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 个答案:

答案 0 :(得分:2)

试试这个: -

经过非常艰苦的努力终于找到了解决方案。我在ubuntu12.04中右键单击子文件夹整个文件夹。

但之后我尝试选择所有图像/文件,然后将它们压缩到新文件夹。 通过上面的代码,我能够成功提取所有文件。

谢谢......