2011-11-18 30 views
2

解壓縮我設法透過這個簡單的代碼在java中的zip文件:成功創建文件無法通過標準的壓縮工具

BufferedInputStream origin = null; 
FileOutputStream dest = new FileOutputStream(zipFile); 

ZipOutputStream out = new ZipOutputStream(new BufferedOutputStream(dest)); 
out.setMethod(ZipOutputStream.DEFLATED); 
out.setLevel(5); 

byte data[] = new byte[BUFFER]; 
FileInputStream fi = new FileInputStream(file); 
origin = new BufferedInputStream(fi, BUFFER); 

ZipEntry entry = new ZipEntry(file.getName()); 
out.putNextEntry(entry); 

int count; 
while ((count = origin.read(data, 0, BUFFER)) != -1) { 
    out.write(data, 0, count); 
} 

out.closeEntry(); 
origin.close(); 
out.close(); 

zip文件。然而,當我試圖把它解壓使用WinZip或其他一些工具,我得到一個錯誤:

Central and local directory mismatch for file "my_file" (general 
purpose flags - local:808 hex central: 8 hex). 
Severe Error: Local and central GPFlags values don't match. 

什麼是真正奇怪的,WinRAR和內部Win7的拉鍊,當我解壓縮文件沒有顯示出任何錯誤。

我在做什麼錯?有人有這個問題嗎? 非常感謝!

+0

發現相關的問題,我也是在Android 2.3的用java:http://stackoverflow.com/questions/7407695/android-2-3-zip-problems-with-general-purpose-flags – vitalnik

回答

1

必須是out.close丟失。

+0

抱歉,它實際上在那裏。編輯原文。 – vitalnik

0

我想你忘了關閉zipentry。

out.closeEntry(); 
origin.close(); 
out.close(); 
+0

剛剛嘗試過。解壓縮時出現同樣的錯誤。不管怎麼說,還是要謝謝你! – vitalnik