java - 通用标志的 Android 2.3 ZIP 问题

标签 java android file zip android-2.3-gingerbread

我在 Android 上创建了一个应用程序,该应用程序将 Activity 记录到文件中。我可以选择导出文件,所以我将文件保存在 .zip 中。如果有超过 1 个文件要添加到 .zip,我会收到以下错误。

(通用标志 - 本地:808 十六进制中央:8 十六进制)。 本地和中央 GPFlags 值不匹配。

这只发生在 Android 2.3 和使用 winzip 或 7zip 的情况下。我可以使用 Windows 资源管理器或 winrar 绕过这个问题,但我想解决这个问题而不是避免它。

在 Android 2.2 设备上使用相同的应用程序不会发生这种情况。

我四处搜索,发现了一些关于加密的评论,但我没有加密任何东西。我还发现了一些关于更新某些库等的评论,但我使用的是 Android sdk 11 和 java jdk 1.6.0_25。

我尝试了 2 个不同的代码,结果相同

int count = log_.getLogFileList(files_);
if (count > 0)
{                       
String inFileName;
File inFile;
String phoneNumLast =OsmoService.getAccountString(OsmoService.context).substring(6);
long date = files_.get(count - 1).lastModified();
SimpleDateFormat formatter = new SimpleDateFormat("MMddHHmmss");                     
String outdt = new String(formatter.format(new Date(date)));
String outFileName = new String("Dir Name" + "//" + "PREFIX" + "_" + outdt + ZIP_SUFFIX);

File outFile = new File(outFileName);                   
ZipOutputStream zos = new ZipOutputStream( new FileOutputStream( outFile ) );
BufferedOutputStream outBS = new BufferedOutputStream(zos, 8192 );

for (int idx = (count - 1); (idx >= 0) && !isCancelled(); idx--)
{
inFile = files_.get(idx);  
BufferedReader inBR = new BufferedReader(new FileReader(inFile), 8192);                     
inFileName = inFile.getName();
Log.v(LOG_TAG, "MailLogFiles - Zipping " + inFileName);

zos.putNextEntry( new ZipEntry(inFileName));
int zix;
while ( (zix = inBR.read()) != -1 )
outBS.write(zix);
outBS.flush();       
zos.closeEntry();    
inBR.close();
}
outBS.close();

还有这个

public static void compressFileList( String[] inFiles, String outFile )
throws IOException
{
ZipOutputStream zos = new ZipOutputStream(
new BufferedOutputStream( new FileOutputStream( outFile ) ));
byte data[] = new byte[2048];

  for (int i = 0; i < inFiles.length; i++)
  {
     BufferedInputStream in = new BufferedInputStream( new FileInputStream( inFiles[i] ) );
     zos.putNextEntry( new ZipEntry(inFiles[i]) );
     int count;
     while( ( count = in.read( data, 0, data.length ) ) != -1 )
        zos.write(data, 0, count);
     zos.closeEntry();
     in.close();
  }
  zos.close();
}

最佳答案

我认为这是由一个已报告的错误引起的,该错误将在 Ice Cream Sandwich 中修复: http://code.google.com/p/android/issues/detail?id=20214

关于java - 通用标志的 Android 2.3 ZIP 问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7407695/

相关文章:

java - 您离不开的 IntelliJ IDEA 社区版插件

java - 在 html 中加载带有 Jess 规则的 java 小程序

java - NotReadablePropertyException : Invalid property 'productss' of bean class [java. util.ArrayList]

java - 如何解决com.android.internal.R.drawable.hover_tooltip_bg?

c - 在 C 中具有动态位置的 fopen() 函数

eclipse - 文件消失,可能与 Eclipse 有关

Java - 字节缓冲区内存不足

Java字符错误: cannot find symbol

android - Ionic2 RC4,在生产模式下找不到插件

java - 带进度条的通知无法展开(Nougat+)