응용 프로그램이 있는데, zip을 다운로드하고 SDCard에서 파일을 압축 해제합니다. 모두 잘 작동하지만 내의 동료는 자신의 맥 (사자)에 zip 파일을 생성 할 때, 내 모든 파일은안드로이드는 Mac에서 압축 된 파일을 압축 해제합니다.
크기가 : -1
CRC : -1
compressedsize을 : -1
그리고 내 sdcard에 파일을 쓸 수 없습니다. 두 zip은 정확히 같은 내용을 가지고 있지만 유일한 차이점은 원래 zip으로 압축 된 곳입니다. 내가 파일을 압축 해제 곳 코드입니다 :
public class UnzipTask extends AsyncTask<String, Integer, Void> {
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();
}
}
나는 7 PC 내 창에 두 파일을 압축을 해제 할 수 있습니다
1) 노트의 몇
2) 내 동료가 Mac에서 파일을 모두 압축 해제 할 수 있습니다.
3) 유일한 문제는 다음과 같습니다. o N 안드로이드 나는 MAC (가) 작성하는 zip 파일을 ... 압축을 풀 수 없습니다
질문 :이
사람이 Mac에서 압축 된 zip 파일이 잘못된 크기를 가지고 이유를 알고 있나요? 내 Unzipping 프로세스 (안드로이드에서) 일부 코드가 누락 되었습니까?
원하는 경우 출력 보여 매우 작은 APK뿐만 아니라, 여기에 지퍼를 다운로드 할 수 있습니다
편집 : 업데이트 된 링크
웹 호스트에서 샘플 zip 파일 다운로드를 일시 중단했습니다. – Barend
감사! 샘플 파일을 업데이트했습니다. – Entreco