我在 Android 上做了一个应用程序,这个应用程序将活动记录到文件中。我可以选择导出文件,因此我将文件保存在 .zip 中。如果要添加到 .zip 的文件超过 1 个,我会收到以下错误。
(通用标志 - 本地:808 hex 中央:8 hex)。本地和中心 GPFlags 值不匹配。
这仅在 Android 2.3 和使用 winzip 或 7zip 时发生。我可以使用 windows explorer 或 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();
}