解壓文件

 
下面這個例子是將一個.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("解壓文件成功");
 }
}
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章