开发者

java.util.zip.ZipException: Central Directory Entry not found

I have a code which runs absolutely fine on emulator but when I run it on Samsung Galaxy Tab, it gives Exception.

I am receiving one compressed zip file from server via socket and than I am extracting these file. If I compress and send two or three text files it runs fine on both i.e. emulator and Galaxy Tab.

But if I compress and send some small image file with text or two image files it gives: >java.util.zip.ZipException: Central Directory Entry not found < on Galaxy Tab but no error on emulator. Zip file size does not exceeds 32 KB and I am sure that file is being received correctly. Here is my uncompressor code

package com.vsi.vremote;

import java.io.BufferedOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStr开发者_运维问答eam;
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);
    }
}

Note: I just checked it on my HTC WildFire, it is also working on this mobile but galaxy TAB :(


java.util.zip.ZipException: Central Directory Entry not found

Its only adding those file into a zip file (see screenshow) but i have to make a zip file from those zip file parts. I simply devided my zip file into parts and uploaded on the server. now i want to download these files in the my app and rebuild the zip file into the app.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜