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

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

用JAVA解壓ZIP

2019-11-18 13:22:46
字體:
來源:轉載
供稿:網友

  關于解壓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./n");
   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");
   }
  }
  
  /**
   * @dll.import("USER32", auto)
   */
  public static native int MessageBox(int hWnd, String lpText, String lpCaption, int uType);
  }
  
  以上程序在WIN98&VJ6.0測試通過.

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 隆尧县| 饶河县| 建昌县| 江油市| 琼结县| 兴义市| 三门峡市| 开封市| 离岛区| 商丘市| 乐都县| 日土县| 顺昌县| 炎陵县| 西昌市| 田东县| 饶平县| 美姑县| 阿荣旗| 介休市| 华亭县| 陆良县| 十堰市| 寿阳县| 广昌县| 乌拉特后旗| 三亚市| 和静县| 信宜市| 池州市| 察雅县| 三河市| 金坛市| 临朐县| 中方县| 醴陵市| 西青区| 临沧市| 乐业县| 额尔古纳市| 莲花县|