作者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://webptt.com/cn.aspx?n=bbs/java/M.1434103071.A.6AF.html
1F:推 omidofor: 其实我觉得你可以买一本Java工具书,看完前面五章+档案 06/12 19:03
2F:→ omidofor: I/O的章节,这个问题你就知道怎麽解了。 06/12 19:04
3F:→ Killercat: 你想问的重点应该都在10 11行.... 06/12 22:40
4F:→ ptt860325: 不好意思,基本上我看不太懂我自己抄来的程式码... 06/13 03:32