200字范文,内容丰富有趣,生活中的好帮手!
200字范文 > android压缩工具 mac Android解压缩在Mac上压缩的文件

android压缩工具 mac Android解压缩在Mac上压缩的文件

时间:2024-07-16 18:42:57

相关推荐

android压缩工具 mac Android解压缩在Mac上压缩的文件

我有一个应用程序,它下载一个zip并解压缩我SDCard上的文件.

一切正常,但是当我的同事在他的Mac(狮子)上创建zip文件时,我的所有文件都有

大小:-1

CRC:-1

compressedsize:-1

我无法将文件写入我的SD卡.两个拉链具有完全相同的内容,唯一的区别在于它们最初压缩的位置.这是我解压缩文件的代码:

public class UnzipTask extends AsyncTask {

private static final String TAG = UnzipTask.class.getSimpleName();

private String mDestLocation;

private ZipListener mListener;

private Context mCtx;

private int mCallbackId;

public UnzipTask(Context context, ZipListener listener, File dir)

{

mCtx = context;

mListener = listener;

mDestLocation = dir.getAbsolutePath() + "/";

}

public void setId(int id)

{

mCallbackId = id;

}

@Override

protected Void doInBackground(String... arg0) {

try {

String file = arg0[0];

InputStream is = mCtx.getAssets().open(file);

unzipFile(is);

} catch (IOException e) {

e.printStackTrace();

} catch (Exception e) {

e.printStackTrace();

}

return null;

}

/**

* Private function that ensures a directory exist

* @param dir

*/

private void _dirChecker(String dir) {

File f = new File(mDestLocation + dir);

if (!f.isDirectory()) {

f.mkdirs();

}

}

private void unzipFile(InputStream input) throws Exception {

ZipInputStream zin = new ZipInputStream(input);

ZipEntry ze = null;

while ((ze = zin.getNextEntry()) != null) {

Log.v(TAG, "Unzipping " + ze.getName());

if(mListener != null)

{

mListener.onUnzipped(mCallbackId, ze.getName(), ze.g etSize(), ze.getCrc(), ze.getCompressedSize());

}

if (ze.isDirectory()) {

_dirChecker(ze.getName());

} else if (ze.getCompressedSize() > 0 && ze.getSize() > 0 && ze.getCrc() != 0.0) {

// If size=-1 -> writing to disk fails

String fileOutput = mDestLocation + ze.getName();

FileOutputStream fout = new FileOutputStream(fileOutput);

int read = 0;

byte[] buffer = new byte[(int) ze.getSize()];

while ((read = zin.read(buffer)) >= 0) {

fout.write(buffer, 0, read);

}

zin.closeEntry();

fout.close();

} else {

Log.v(TAG, "Skipping entry" + ze.getName());

}

}

}

zin.close();

}

}

几个笔记

1)我可以在Windows 7上解压缩这两个文件

2)我的同事可以在他的Mac上解压缩这两个文件

3)唯一的问题是,在Android上我无法解压缩MAC创建的zip文件…

题:

有谁知道为什么在Mac上压缩的zip文件有这些无效的大小?我的解压缩过程(在Android上)是否遗漏了一些代码?

如果你愿意,你可以在这里下载拉链,以及一个非常小的apk来显示输出:

编辑:更新链接

解决方法:

该问题与版本有关.让我从我的Mac(10.8)的一些输出开始:

~ $zipinfo -m test_mac.zip

Archive: test_mac.zip 1694 bytes 8 files

drwxr-xr-x 2.1 unx 0 bx 0% stor 10-Aug-12 01:11 test_win/

-rwxr-xr-x 2.1 unx 46 bX 20% defN 10-Aug-12 01:11 test_win/index.html

drwxrwxr-x 2.1 unx 0 bx 0% stor 10-Aug-12 01:12 __MACOSX/

drwxrwxr-x 2.1 unx 0 bx 0% stor 10-Aug-12 01:12 __MACOSX/test_win/

-rw-r--r-- 2.1 unx 211 bX 37% defN 10-Aug-12 01:11 __MACOSX/test_win/._index.html

-rwxr-xr-x 2.1 unx 9 bX-21% defN 10-Aug-12 01:10 test_win/version.txt

-rw-r--r-- 2.1 unx 211 bX 37% defN 10-Aug-12 01:10 __MACOSX/test_win/._version.txt

-rw-r--r-- 2.1 unx 211 bX 37% defN 10-Aug-12 01:11 __MACOSX/._test_win

8 files, 688 bytes uncompressed, 450 bytes compressed: 34.6%

~ $zipinfo -m test_win.zip

Archive: test_win.zip 1678 bytes 8 files

drwx--- 3.1 fat 0 bx 0% stor 10-Aug-12 09:11 test_win/

-rw-a-- 3.1 fat 46 bx 20% defN 10-Aug-12 09:11 test_win/index.html

-rw-a-- 3.1 fat 9 bx-21% defN 10-Aug-12 09:10 test_win/version.txt

drwx--- 3.1 fat 0 bx 0% stor 10-Aug-12 09:12 __MACOSX/

-rw-a-- 3.1 fat 211 bx 37% defN 10-Aug-12 09:11 __MACOSX/._test_win

drwx--- 3.1 fat 0 bx 0% stor 10-Aug-12 09:12 __MACOSX/test_win/

-rw-a-- 3.1 fat 211 bx 37% defN 10-Aug-12 09:11 __MACOSX/test_win/._index.html

-rw-a-- 3.1 fat 211 bx 37% defN 10-Aug-12 09:10 __MACOSX/test_win/._version.txt

8 files, 688 bytes uncompressed, 450 bytes compressed: 34.6%

看看第二个字段(mac文件中的2.1和win文件中的3.1).这是压缩文件的ZIP存档格式版本. java.util.zip实现仅支持版本2.50及更高版本的ZIP文件格式(请参阅此StackOverflow).

Mac的Compress …菜单选项使用低于Java实现支持的版本(2.1仍然在10.8中使用).

告诉你的同事使用命令行工具(例如zip -r myfile.zip directory_to_compress /),你应该得到Android应用程序可以膨胀的输出.

标签:android,macos,zipfile,windows-7,osx-lion

来源: https://codeday.me/bug/0901/1786627.html

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。