解压文件
下面这个例子是将一个.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 void extZipFileList(String zipFileName, String extPlace) {
try { ZipInputStream in = new ZipInputStream(new FileInputStream(
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 { FileOutputStream os = new FileOutputStream(extPlace
+ entryName); byte[] buf = new byte[1024];
int len; while ((len = in.read(buf)) > 0) { os.write(buf, 0, len); } os.close(); in.closeEntry(); } } } catch (IOException e) { 本文出自 51CTO.COM技术博客} System.out.println("解压文件成功"); } } |


林行天下
博客统计信息
热门文章
最新评论
友情链接