<%@ page contentType="text/html; charset=gb2312"%> 比较完善的用JAVA解压ZIP
网站公告:   ◆北天JAVA技术网热情为java爱好者服务,本网内容包括JAVA(JSP、servlet、EJB、webservice、j2ee、javabean、应用服务器、JavaScript),数据库(MYSQL、SQL Server、Sybase、Oracle、DB2、数据库综合知识),设计研究(设计模式、Struts、Spring、Hibernate、设计框架、设计综合知识),WEB2.0新技术(主要介绍AJAX),以及各种技术的入门、实例、例子等等,欢迎各位多来坐坐!◆  诚邀各位JAVA爱好者加盟!◆  本网站内容丰富,更新快,保证每周20篇以上!  
加入收藏
设为首页
联系站长
承接项目
  相关资源:网站首页 | 免费培训学院 | 技术论坛 | JAVA聊天室 | 作家专栏 | 开发工具 | 认证考试 | 会员俱乐部
  JAVA技术初学者园地 | jsp与servlet | javascript | Java源代码 | EJB | web service | 应用服务器 | JAVA综合知识
  设计研究设计模式 | 设计框架 | Struts | Spring | Hibernate | 开源项目 | 面向对象设计 | 设计综合知识
  数 据 库MYSQL | SQL Server | Sybase | Oracle | DB2 | Informix | Access | 数据库综合知识
  其他资源:AJAX新技术 | 网站开发 | ERP软件 | OA办公软件 | 商业智能BI | 开发综合知识 | 承接项目 | 项目试用

 
 
比较完善的用JAVA解压ZIP
     发布者: 发布时间:2006-07-04

以下是本人编写的关于解压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

(转载文章请保留出处:北天JAVA技术网(www.java114.com))
 
更多精彩文章:
JavaBeans 程序开发基础教程
javascript对控件只读属性的设置
javascript日期验证
检查指定Text输入框的值是否是数值型数据
javascript 验证表单的数据是否为数字
用JavaScrpt实现文件夹轻松加密
 
        
标 题:   
内 容:   
 
                                  
 
免责声明:该文章由网友发表,如果对您造成侵权,请联系站长

首页 - 承接项目 - 网站地图 - 联系我们 -
版权所有北天JAVA技术工作室 ICP证号:粤ICP备06079815号