Android 2.3的ZIP问题通用标志 [英] Android 2.3 ZIP problems with general purpose flags

查看:336
本文介绍了Android 2.3的ZIP问题通用标志的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Android上的应用程序和该应用程序会记录活动纳入文件。我必须将文件导出,所以我的文件保存在一个.zip一个选项。如果有超过1文件,加入到该.zip,我碰到下面的错误。

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

这仅与Android 2.3及使用WinZip或7zip的发生。我可以使用Windows Explorer或winrar的绕过这个问题,但我想解决这个问题,而不是避开它。

这不会发生使用的是Android 2.2设备上的同一个应用程序。

我搜索周围了一圈,发现有关加密的一些意见,但我没有任何加密。我还发现,在某些更新库和一些意见,但等我使用Android SDK中11和JAVA JDK 1.6.0_25。

我试过2个不同的codeS具有相同的结果。

 诠释计数= log_.getLogFileList(files_);
如果(计数大于0)
{
串inFileName;
文件INFILE;
串phoneNumLast = OsmoService.getAccountString(OsmoService.context).substring(6);
长日期= files_.get(计数 - 1).lastModified();
SimpleDateFormat的格式化=新的SimpleDateFormat(MMddHHmmss);
字符串outdt =新的String(formatter.format(新日期(日期)));
字符串outFileName =新的String(目录名称+//+preFIX+_+ outdt + ZIP_SUFFIX);文件不过outFile =新的文件(outFileName);
ZipOutputStream ZOS =新ZipOutputStream(新的FileOutputStream(不过outFile));
的BufferedOutputStream outBS =新的BufferedOutputStream(ZOS,8192);对(INT IDX =(计数 - 1);!(IDX&GT = 0)及&放大器; isCancelled(); idx--)
{
INFILE = files_.get(IDX);
的BufferedReader inBR =新的BufferedReader(新的FileReader(INFILE),8192);
inFileName = inFile.getName();
Log.v(LOG_TAGMailLogFiles - 荏苒+ inFileName);zos.putNextEntry(新的ZipEntry(inFileName));
INT ZIX;
而((ZIX = inBR.read())!= - 1)
outBS.write(ZIX);
outBS.flush();
zos.closeEntry();
inBR.close();
}
outBS.close();

 公共静态无效的COM pressFileList(字符串[] inFiles,弦乐不过outFile)
抛出IOException异常
{
ZipOutputStream ZOS =新ZipOutputStream(
新的BufferedOutputStream(新的FileOutputStream(不过outFile)));
字节的数据[] =新的字节[2048];  的for(int i = 0; I< inFiles.length;我++)
  {
     在BufferedInputStream为=新的BufferedInputStream(新的FileInputStream(inFiles [I]));
     zos.putNextEntry(新的ZipEntry(inFiles [I]));
     诠释计数;
     而((计数= in.read(数据,0,data.length))!= -1)
        zos.write(数据0,计);
     zos.closeEntry();
     附寄();
  }
  zos.close();
}


解决方案

我认为这是一个错误报告将固定在Ice Cream Sandwich的原因造成的:
HTTP://$c$c.google.com/p /安卓/问题/细节?ID = 20214

I made an application on Android and this application logs the activity into files. I have an option to export the files so I save the files in a .zip. If there is more than 1 file to add to the .zip, I get the following error.

(general purpose flags - local: 808 hex central: 8 hex). Local and central GPFlags values don't match.

This only happens with Android 2.3 and using winzip or 7zip. I can bypass this problem using windows explorer or winrar but I would like to solve the problem and not avoid it.

It does not happen using the same application on an Android 2.2 device.

I searched around around and found some comments about encrypting but I am not encrypting anything. I also found some comments on updating certain libraries and such but I'm using Android sdk 11 and java jdk 1.6.0_25.

I tried 2 different codes with the same result

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();

and this

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();
}

解决方案

I think this is caused by a reported bug that will be fixed in Ice Cream Sandwich: http://code.google.com/p/android/issues/detail?id=20214

这篇关于Android 2.3的ZIP问题通用标志的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆