我在Android上提出的申请,这应用程序日志活动到文件中。 我必须将文件导出,所以我将文件保存在一个.zip的选项。 如果有不止一个文件添加到该.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个不同的代码具有相同的结果
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();
}