下面這個例子是將一個.zip的文件解壓。
import java.io.*;
import java.util.zip.*;
public class ReadZip2 {
public static void main(String[] args) {
ReadZip2 zip=new ReadZip2();
zip.extZipFileList("d://abc.zip", "d://");
}
public static void main(String[] args) {
ReadZip2 zip=new ReadZip2();
zip.extZipFileList("d://abc.zip", "d://");
}
public void extZipFileList(String zipFileName, String extPlace) {
try {
try {
ZipInputStream in = new ZipInputStream(new FileInputStream(
zipFileName));
ZipEntry entry = null;
zipFileName));
ZipEntry entry = null;
while ((entry = in.getNextEntry()) != null) {
String entryName = entry.getName();
if (entry.isDirectory()) {
File file = new File(extPlace + entryName);
file.mkdirs();
System.out.println("創建文件夾:" + entryName);
} else {
String entryName = entry.getName();
if (entry.isDirectory()) {
File file = new File(extPlace + entryName);
file.mkdirs();
System.out.println("創建文件夾:" + entryName);
} else {
FileOutputStream os = new FileOutputStream(extPlace
+ entryName);
+ entryName);
byte[] buf = new byte[1024];
int len;
while ((len = in.read(buf)) > 0) {
os.write(buf, 0, len);
}
os.close();
in.closeEntry();
}
}
int len;
while ((len = in.read(buf)) > 0) {
os.write(buf, 0, len);
}
os.close();
in.closeEntry();
}
}
} catch (IOException e) {
}
System.out.println("解壓文件成功");
}
}
}
System.out.println("解壓文件成功");
}
}