2
Android에서 파일을 압축 해제하는 데 문제가 있습니다. - 크기 0 (HTML 파일 .jpg)이Android - 일부 압축 해제 된 파일의 크기가 0입니다 (비어 있음)
public void unzip() {
try {
FileInputStream fin = new FileInputStream(_zipFile);
BufferedInputStream in = new BufferedInputStream(fin);
ZipInputStream zin = new ZipInputStream(in);
ZipEntry ze = null;
while ((ze = zin.getNextEntry()) != null) {
Log.v("Decompress", "Unzipping " + ze.getName());
if(ze.isDirectory()) {
_dirChecker(ze.getName());
} else {
FileOutputStream fout = new FileOutputStream(_location + ze.getName());
BufferedOutputStream out = new BufferedOutputStream(fout);
byte[] buffer = new byte[1024];
int length;
while ((length = zin.read(buffer,0,1024)) >= 0) {
out.write(buffer,0,length);
}
/* while ((length = zin.read(buffer))>0) {
out.write(buffer, 0, length);
}*/
/*for (int c = zin.read(); c != -1; c = zin.read()) {
fout.write(c);
}*/
zin.closeEntry();
fout.close();
}
}
zin.close();
} catch(Exception e) {
Log.e("Decompress", "unzip", e);
}
}
작은 파일 (10kB에서보다 작은) 빈처럼 압축을 풀면됩니다 여기에 코드입니다. 다른 파일은 괜찮습니다. 이 동일한 코드를 사용하지만 버퍼가없는 경우 모든 파일이 ok입니다. 버퍼없이 압축을 풀면 너무 오래 실행되므로 문제가되지 않습니다. 파일은 실제 장치의 SD 카드에 저장됩니다. 나는 이미 작은 버퍼 크기 (심지어 새로운 바이트 [2])를 설정하려고 시도했다. 미리 감사드립니다 ...
덕분에, 문제가 해결! – vlatko
제 친구를 환영합니다 .. –