国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學院 > 開發設計 > 正文

比較完善的用JAVA解壓ZIP

2019-11-18 15:12:29
字體:
來源:轉載
供稿:網友

以下是本人編寫的關于解壓Zip文件的類,解決了中文問題及提高了解壓的速度.希望對大家有所幫助,假如覺的好,請給我投一票,假如有什么更好方法,請通知我 ,謝謝.

import java.io.*;
import java.util.*;
import java.util.zip.*;
import sun.io.*;

public class linzip
{
 public static String make8859toGB(String str)
 {
  try{
   String str8859 = new String(str.getBytes("8859_1"),"GB2312");
   return str8859;
  }catch(UnsupportedEncodingException ioe){
   return str;
  }
 }
 
 public static void main(String[] args)
 {
  if (args.length < 1){
   System.err.   System.exit(-1);
  }
  
  
  File infile = new File(args[0]);

  try{
   //檢查是否是ZIP文件
   ZipFile zip = new ZipFile(infile);
   zip.close();
   
   //建立與目標文件的輸入連接
   ZipInputStream in = new ZipInputStream(new FileInputStream(infile));
   ZipEntry file = in.getNextEntry();
   
     
   int i =infile.getAbsolutePath().lastIndexOf('.');
   String dirname = new String();
   if ( i != -1 )
    dirname = infile.getAbsolutePath().substring(0,i);
   else
    dirname = infile.getAbsolutePath();
   File newdir = new File(dirname);
   newdir.mkdir();
   
   byte[] c = new byte[1024];
   int len;
   int slen;
   
   while (file != null){
    
    i = make8859toGB(file.getName()).replace('/','/').lastIndexOf('/');
    if ( i != -1 ){
     File dirs = new File(dirname+File.separator+make8859toGB(file.getName()).replace('/','/').substring(0,i));
     dirs.mkdirs();
     dirs = null;
    }
    
    System.out.print("Extract "+make8859toGB(file.getName()).replace('/','/')+" ........  ");
    
    if (file.isDirectory()){
     File dirs = new File(make8859toGB(file.getName()).replace('/','/'));
     dirs.mkdir();
     dirs = null;
    }
    else{ 
     FileOutputStream out = new FileOutputStream(dirname+File.separator+make8859toGB(file.getName()).replace('/','/'));
     while((slen = in.read(c,0,c.length)) != -1)
      out.write(c,0,slen);
     out.close();
    }
    System.out.print("O.K.");
    file = in.getNextEntry();
   }
   in.close();
  }catch(ZipException zipe){
   MessageBox(0,infile.getName()+"不是一個ZIP文件!","文件格式錯誤",16);
  }catch(IOException ioe){
   MessageBox(0,"讀取"+args[0]+"時錯誤!","文件讀取錯誤",16);
  }catch(Exception i){
    System.out.println("over");
  }
 }



發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 荆州市| 临沂市| 水富县| 乌什县| 高淳县| 东山县| 区。| 潮安县| 通化市| 大新县| 霞浦县| 邢台县| 邵阳市| 南漳县| 都江堰市| 陵水| 东宁县| 手游| 锦州市| 申扎县| 得荣县| 如皋市| 辽宁省| 崇明县| 搜索| 尉氏县| 中阳县| 潞西市| 太原市| 怀化市| 邢台市| 玉树县| 襄汾县| 珲春市| 五大连池市| 常州市| 天长市| 武宁县| 永丰县| 南安市| 信丰县|