作者ptt860325 (五月)
看板java
標題[問題] 解壓縮Jar檔案
時間Fri Jun 12 17:57:49 2015
我找了一段可以解壓縮 Zip 的程式碼來用,他可以成功解壓縮Jar但如果要解壓縮的檔案
內有資料夾他就會放棄解壓縮這個檔案,請問要如何控制要解壓縮哪些附檔名即可,或是
全部都解壓縮,我在寫一段把我不要的刪除,當然如果有辦法達到前者的要求就太棒了!
-------------------------------程式碼-----------------------------------------
void 解壓縮(String 檔案位置) {
try {
ZipInputStream Zin = new ZipInputStream(new FileInputStream(檔案位置));
System.out.println(檔案位置);
BufferedInputStream Bin = new BufferedInputStream(Zin);
String Parent = 解壓縮輸出位置;
File Fout = null;
ZipEntry entry;
try {
while ((entry = Zin.getNextEntry()) != null && !entry.isDirectory()) {
Fout = new File(Parent, entry.getName());
if (!Fout.exists()) {
(new File(Fout.getParent())).mkdirs();
}
FileOutputStream out = new FileOutputStream(Fout);
BufferedOutputStream Bout = new BufferedOutputStream(out);
int b;
while ((b = Bin.read()) != -1) {
Bout.write(b);
}
Bout.close();
out.close();
}
Bin.close();
Zin.close();
} catch (IOException e) {
e.printStackTrace();
}
} catch (FileNotFoundException e) {
e.printStackTrace();
}
--
※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 175.182.233.107
※ 文章網址: https://www.ptt.cc/bbs/java/M.1434103071.A.6AF.html
推 omidofor: 其實我覺得你可以買一本Java工具書,看完前面五章+檔案 06/12 19:03
→ omidofor: I/O的章節,這個問題你就知道怎麼解了。 06/12 19:04
→ Killercat: 你想問的重點應該都在10 11行.... 06/12 22:40
→ ptt860325: 不好意思,基本上我看不太懂我自己抄來的程式碼... 06/13 03:32