java的一个ZIP解压问题求解。
我现在有个文件加,里面放的都是zip文件,我现在想要的不是要每次输入文件名的地址,而是让程序自动找到zip文件然后解压,然后放到指定的文件加里。我现在写的程序是只能一个一个的输入文件名然后他才能执行解压缩。
我的代码如下。
public static void UnZIP(String sourceFileName, String desDir) throws ZipException, IOException {
// erstellen ein Object von ZIP
ZipFile zf = new ZipFile(new File(sourceFileName));
// alle Entries bekommen
Enumeration<ZipEntry> en = (Enumeration<ZipEntry>) zf.entries();
int length = 0;
byte[] b = new byte[2048];
while (en.hasMoreElements()) {
ZipEntry ze = en.nextElement();
File f = new File(desDir + ze.getName());
if (ze.isDirectory()) {
f.mkdirs();
} else {
if (!f.getParentFile().exists()) {
f.getParentFile().mkdirs();
}
OutputStream outputStream = new FileOutputStream(f);
java.io.InputStream inputStream = zf.getInputStream(ze);
while ((length = inputStream.read(b)) > 0)
outputStream.write(b, 0, length);
inputStream.close();
outputStream.close();
}
}
zf.close();
}
那位大虾能帮忙改改。