注册 | 登录 忘记密码? 51cto首页 | 博客 | 论坛 | 招聘
热点文章 Exchange服务器系列课程之..
 帮助

解压文件


2007-12-01 19:47:50
 标签:zip 文件 解压   [推送到技术圈]

 
下面这个例子是将一个.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) {
  }
  System.out.println("解压文件成功");
 }
}




    文章评论
 
 

发表评论

昵   称:
验证码:  点击图片可刷新验证码  博客过2级,无需填写验证码
内   容: