![](/img/trans.png)
[英]Still An Issue? - java.util.zip.ZipException: Central Directory Entry not found
[英]java.util.zip.ZipException: Central Directory Entry not found
我有一個可以在模擬器上完全正常運行的代碼,但是當我在Samsung Galaxy Tab上運行它時,它會給出Exception。
我通過套接字從服務器收到一個壓縮的zip文件,然后解壓縮這些文件。 如果我壓縮並發送兩個或三個文本文件,則可以在模擬器和Galaxy Tab上正常運行。
但是,如果我壓縮並發送一些帶有文本或兩個圖像文件的小圖像文件,它會給出:> java.util.zip.ZipException:在Galaxy Tab上找不到中央目錄條目<,但是在模擬器上沒有錯誤。 壓縮文件的大小不超過32 KB,並且我確定該文件已正確接收。 這是我的解壓器代碼
package com.vsi.vremote;
import java.io.BufferedOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.Enumeration;
import java.util.zip.ZipEntry;
import java.util.zip.ZipFile;
import android.content.Context;
import android.util.Log;
public class UnCompressor {
private static final String TAG = "UnCompressor";
Context context;
public UnCompressor(Context context) {
this.context = context;
}
private final void copyInputStream(InputStream in, OutputStream out)
throws IOException {
byte[] buffer = new byte[1024];
int len;
while ((len = in.read(buffer)) >= 0)
out.write(buffer, 0, len);
in.close();
out.close();
}
public final String[] unCompress(String name) {
try {
Log.d(TAG, "Uncompress called");
ZipFile zipFile = new ZipFile(context.getFileStreamPath(name));
Log.d(TAG, "Zip file created");
Enumeration entries = zipFile.entries();
String fileNames[] = new String[zipFile.size()];
int counter = 0;
Log.d(TAG, "Loop strting");
while (entries.hasMoreElements()) {
Log.d(TAG, "Getting next entry");
ZipEntry entry = (ZipEntry) entries.nextElement();
Log.d(TAG, "Extracting file: " + entry.getName());
copyInputStream(
zipFile.getInputStream(entry),
new BufferedOutputStream(context.openFileOutput(
entry.getName(), Context.MODE_PRIVATE)));
fileNames[counter++] = entry.getName();
}
zipFile.close();
return fileNames;
} catch (IOException ioe) {
System.err.println("Unhandled exception:");
ioe.printStackTrace();
return null;
}
}
public final void delete(String fileName) {
context.deleteFile(fileName);
}
}
注意:我剛剛在HTC WildFire上進行了檢查,它也可以在此移動設備上使用,但銀河TAB :(
它僅將那些文件添加到zip文件中(請參閱屏幕顯示),但是我必須從這些zip文件部分中創建一個zip文件。 我只是將zip文件分成幾部分,然后上傳到服務器上。 現在我想在我的應用程序中下載這些文件,然后將zip文件重建到該應用程序中。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.