2011-04-12 230 views
0

我有一个代码在模拟器上运行得非常好,但是当我在Samsung Galaxy Tab上运行它时,它会给出异常。
我正在通过套接字从服务器接收一个压缩的zip文件,而我正在提取这些文件。如果我压缩并发送两个或三个文本文件,它可以在模拟器和Galaxy Tab上正常运行。
但是,如果我压缩并发送一些带有文本或两个图像文件的小图像文件,它会给出:> java.util.zip.ZipException:在Galaxy选项卡上找不到中央目录条目<,但模拟器上没有错误。 Zip文件大小不超过32 KB,我确信该文件正在正确接收。这里是我的uncompressor代码java.util.zip.ZipException:没有找到中央目录条目

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野火,它也正在研究这个手机,但Galaxy Tab的:(

回答

0

看看也许这是关系到Central Directory Entry not found (ZipException),看看答案有帮助的

+0

问题解决了,我从服务器接收这个文件并保存在SD卡上。我没有正确接收,在SD卡上写入时出现了一些错误的逻辑,这就是我得到ZIP Exception的原因。 – 2011-05-18 12:17:06

0

enter image description here

它唯一的添加这些文件压缩成zip文件(见screenshow),但我必须做出从这些压缩文件部分的zip文件。我只是devided我的zip文件到零件和上传了服务器。现在我想在我的应用程序中下载这些文件,并将zip文件重新编译到应用程序中。

相关问题