日韩黑丝制服一区视频播放|日韩欧美人妻丝袜视频在线观看|九九影院一级蜜桃|亚洲中文在线导航|青草草视频在线观看|婷婷五月色伊人网站|日本一区二区在线|国产AV一二三四区毛片|正在播放久草视频|亚洲色图精品一区

分享

用JAVA解壓ZIP

 小朋 2006-10-30
關(guān)于解壓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.println("Required parameter missing!");
   System.exit(-1);
   }
  
  
   File infile = new File(args[0]);
  
   try{
   //檢查是否是ZIP文件
   ZipFile zip = new ZipFile(infile);
   zip.close();
  
   //建立與目標(biāo)文件的輸入連接
   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測試通過.

    本站是提供個人知識管理的網(wǎng)絡(luò)存儲空間,所有內(nèi)容均由用戶發(fā)布,不代表本站觀點。請注意甄別內(nèi)容中的聯(lián)系方式、誘導(dǎo)購買等信息,謹(jǐn)防詐騙。如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請點擊一鍵舉報。
    轉(zhuǎn)藏 分享 獻花(0

    0條評論

    發(fā)表

    請遵守用戶 評論公約

    類似文章 更多