JSPCN主页 | JSP空间 | 网站制作 | JSP下载 | JSP论坛 | JSP教程 | 关于JSPCN | 联系我们
JSP虚拟主机,jsp空间,java空间,java虚拟空间,详细请点击进入
做最专业的JSP中文网站 当前位置首页--JAVA技术--JAVA实例  
文章搜索:
关键字 标题
  
JSP中文网内容管理系统(JCMS)
JSP虚拟主机
网络笔记本
网摘,图片,笔记收藏
虚拟服务器

JSPCN文章目录分类
JSP配置[219]JSP基础[136]
中文问题[69]上传问题[27]
JAVABEAN[46]数据库[212]
文件操作[126]图片声音[17]
JSP其他[57]时间相关[16]
JAVAMAIL[72]STRUTS[144]
开发工具[28]教程系列[157]
JSP实例[89]
JAVA基础[421]APPLET[78]
JAVA网络[179]Applica[115]
Servlet[98]XML[163]
J2ME[257]J2EE[374]
考试相关[63]JAVA线程[90]
EJB[261]Swing[26]
Java API[141]声音图片[28]
异常处理[33]JAVA实例[290]
JAVA类[139]SUN[89]
Hibernate[6]JMX[8]
Spring[34]
本版推荐文章 
本版热点文章 
相关文章链接 
 
比较完善的用JAVA解压ZIP
作者:不详     文章来源:www.jspcn.net
访问次数:1390次     加入时间:2005年10月19日

以下是本人编写的关于解压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();
   
   //建立与目标文件的输入连接
   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");
  }
 }

 /**
  * @dll.import("USER32", auto)
  */
 public static native int MessageBox(int hWnd, String lpText, String lpCaption, int uType);
}

以上程序在WIN98&VJ6.0测试通过.本人E-mail: lsf82@citiz.net

Copyright © 2002-2005 JSPCN.net. All rights reserved.
JSP中文网    备案序号:蜀ICP备05001583号
成都恒海科技发展有限公司    成都市一环路南二段6号新瑞楼三楼8号