Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/390.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 为什么ZipEntry在果冻豆中不起作用_Java_Android_Zip - Fatal编程技术网

Java 为什么ZipEntry在果冻豆中不起作用

Java 为什么ZipEntry在果冻豆中不起作用,java,android,zip,Java,Android,Zip,我有一个140 MB的ZIP文件,包含大约4万个MP3文件。我使用以下代码在ZIP文件中播放某个文件,而不进行解压缩: String fullPath = Environment.getExternalStorageDirectory().getPath() + "_audio_.mp3"; String path = Environment.getExternalStorageDirectory().getPath() + "mySoundFolder"; try {

我有一个140 MB的ZIP文件,包含大约4万个MP3文件。我使用以下代码在ZIP文件中播放某个文件,而不进行解压缩:

String fullPath = Environment.getExternalStorageDirectory().getPath() + "_audio_.mp3";
String path = Environment.getExternalStorageDirectory().getPath() + "mySoundFolder";

try {           
ZipFile zip = new ZipFile(path + "myFile.zip");                     
Enumeration zipEntries = zip.entries();                          
ZipEntry entry = zip.getEntry("myFile" + "/" + currentWord + ".mp3"); 

if (entry != null) {
    Log.i(MAIN_TAG, "entry found: " + entry.getName());   
    InputStream in = zip.getInputStream(entry);  

        File f = new File(fullPath);
        FileOutputStream out = new FileOutputStream(f);     
        IOUtils.copy(in, out);
        byte buffer[] = new byte[4096];
        int read;
        while ((read = in.read(buffer)) != -1)
        { 
        out.write(buffer, 0, read);     
        }                       
            if (f.exists())                         
                {
                    Log.i(MAIN_TAG,"Audio file found!");   
                    final MediaPlayer mp = new MediaPlayer();
                    mp.setDataSource(fullPath); 
                    mp.prepare();
                    mp.setOnBufferingUpdateListener(null);
                    mp.setLooping(false);                   
                    mp.setOnPreparedListener(new OnPreparedListener()
                    { public void onPrepared(MediaPlayer arg0) 
                        { 
                            mp.start();                         
                        Log.i(MAIN_TAG,"Pronunciation finished!");
                        }});                                            

                        }
                    else
                    {
                        Log.i(MAIN_TAG,"File doesn't exist!!"); 
                    }                       
                } 
                else {
                    // no such entry in the zip
                    Log.i(MAIN_TAG, "no such entry in the zip");                
                 }              
            } 
            catch (IOException e) {

                e.printStackTrace();
             Log.i(MAIN_TAG,"IOException reading zip file");                
            }           
        }   
这段代码有两个奇怪的地方:

  • 它在
    android2.2
    中运行完美,但在
    android4.0.3
    中失败。在
    2.2
    中,它会像我预期的那样查找并播放MP3文件,但在
    4.0.3
    中,它一直说在ZIP文件中找不到条目(
    “ZIP中没有这样的条目”
  • 如果我将MP3文件的数量减少到大约100个文件,那么在安卓4.0.3中,它会找到并播放所选的MP3文件 你们能帮我找出问题所在吗


    事先非常感谢。

    最后,我找到了解决这个问题的方法。我将我的zip文件分为两个文件,每个文件包含大约20k个条目。瞧,它又像一个符咒了


    我听说过Java在读取超过64k条目的zip文件中的条目的问题。我不知道为什么我的文件只有大约40k个条目,但它也面临着这个问题

    这段代码在非android环境(例如:PC)上运行良好吗?i、 e,没有zip.getEntry(“myFile”+“/”+currentWord+”.mp3”)在PC上返回一个条目而不是null?我不知道,因为我没有机会这样测试。但是请注意,这个问题只出现在Android 4x中,并且zip文件的条目数超过40k。