Java 为什么ZipEntry在果冻豆中不起作用
我有一个140 MB的ZIP文件,包含大约4万个MP3文件。我使用以下代码在ZIP文件中播放某个文件,而不进行解压缩: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 {
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中没有这样的条目”
)事先非常感谢。最后,我找到了解决这个问题的方法。我将我的zip文件分为两个文件,每个文件包含大约20k个条目。瞧,它又像一个符咒了
我听说过Java在读取超过64k条目的zip文件中的条目的问题。我不知道为什么我的文件只有大约40k个条目,但它也面临着这个问题 这段代码在非android环境(例如:PC)上运行良好吗?i、 e,没有zip.getEntry(“myFile”+“/”+currentWord+”.mp3”)代码>在PC上返回一个条目而不是null?我不知道,因为我没有机会这样测试。但是请注意,这个问题只出现在Android 4x中,并且zip文件的条目数超过40k。