网络编程 | 站长之家 | 网页制作 | 图形图象 | 操作系统 | 冲浪宝典 | 软件教学 | 网络办公 | 邮件系统 | 网络安全 | 认证考试 | 系统进程
Firefox | IE | Maxthon | 迅雷 | 电驴 | BitComet | FlashGet | QQ | QQ空间 | Vista | 输入法 | Ghost | Word | Excel | wps | Powerpoint
asp | .net | php | jsp | Sql | c# | Ajax | xml | Dreamweaver | FrontPages | Javascript | css | photoshop | fireworks | Flash | Cad | Discuz!
当前位置 > 网站建设学院 > 网络编程 > Java
Tag:注入,存储过程,分页,安全,优化,xmlhttp,fso,jmail,application,session,防盗链,stream,无组件,组件,md5,乱码,缓存,加密,验证码,算法,cookies,ubb,正则表达式,水印,索引,日志,压缩,base64,url重写,上传,控件,Web.config,JDBC,函数,内存,PDF,迁移,结构,破解,编译,配置,进程,分词,IIS,Apache,Tomcat,phpmyadmin,Gzip,触发器,socket
网络编程:ASP教程,ASP.NET教程,PHP教程,JSP教程,C#教程,数据库,XML教程,Ajax,Java,Perl,Shell,VB教程,Delphi,C/C++教程,软件工程,J2EE/J2ME,移动开发
本月文章推荐
.利用DES加密算法保护Java源代码.
.ROSE 技术白皮书.
.spring关于底层资源的抽象.
.用Spring JMS使异步消息变得简单.
.编程必备经典:Java常见问题集锦(.
.显示一个java跳转页面.
.用JAI扩展Java的图像处理能力.
.Java咖啡馆(7)——大话面向对象(.
.java程序如何穿透带有密码验证的.
.Java类装载体系中的隔离性.
.文件上传的完全攻略.
.Eclipse 3.0快速上手指南之安装配.
.创建灵活易扩展的J2EE企业应用程.
.Enterprise JavaBeans导论(3).
.对等点如何彼此定位实现交互功能.
.抽象类和方法.
.Java变量类型间的相互转换.
.java使用程序块.
.用jdk自带包操作XML.
.X3D实战基础讲座之十一.

用JAVA解压ZIP

发表日期:2008-1-5



  关于解压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.\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测试通过.
上一篇:Java性能优化 人气:1066
下一篇:数据类型 人气:591
浏览全部Java的内容 Dreamweaver插件下载 网页广告代码 祝你圣诞节快乐 2009年新年快乐