专注于Jsp开发,为Jsp开发提供原动力郑州网站建设 | 网站优化 | 郑州网络公司 | 洛阳网站建设 | 网站建设 | 北京网站建设
jsp空间
    栏目导航:
JAVA 新闻
配制Java环境
JAVA语言基础
JAVA实例教程
JAVA应用技巧
JAVA开发工具
JAVA设计模式
应用服务器
JAVA开发模式
    最近更新:
jsp 实现在线人数统计...
Java实例:JAVA实现屏...
使用JSP生成验证码的源...
在JAVA中实现的二叉树...
Structs2.0 拦截器
Hibernate高级查询实战...
Java定时器Web
使用Java解压缩文件
    点击排行:
主机托管注意事项
企业如何选择主机托管...
主机托管的好处
JSP+AJAX 添加、删除多...
实例解析:Jsp+JavaBe...
代码实例:JSP分页源程...
Tomcat下JSP、Servlet...
谈JSP与XML的交互
使用Java解压缩文件
作者无:   加入时间:2008-11-20 17:20:41   点击次数:3

package chapter03;   import java.io.*;   import java.util.Enumeration;   import java.util.zip.*;   public class Test07 {       static final int BUFFER = 2048;       public static void unZip()throws Exception{           String fileName = "E:\\jdbc.zip";           String filePath = "E:\\aaa\\";           ZipFile zipFile = new ZipFile(fileName);           Enumeration emu = zipFile.entries();           int i=0;           while(emu.hasMoreElements()){               ZipEntry entry = (ZipEntry)emu.nextElement();               //会把目录作为一个file读出一次,所以只建立目录就可以,之下的文件还会被迭代到。                              if (entry.isDirectory()){                   System.out.println("entry is a directory");                   new File(filePath + entry.getName()).mkdirs();                   continue;               }                              BufferedInputStream bis = new BufferedInputStream(zipFile.getInputStream(entry));               File file = new File(filePath + entry.getName());               //加入这个的原因是zipfile读取文件是随机读取的,这就造成可能先读取一个文件               //而这个文件所在的目录还没有出现过,所以要建出目录来。               //File parent = file.getParentFile();               //if(parent != null && (!parent.exists())){               //  parent.mkdirs();               //}               FileOutputStream fos = new FileOutputStream(file);               ObjectOutputStream bos = new ObjectOutputStream(fos);               int count;               byte data[] = new byte[BUFFER];               while ((count = bis.read(data, 0, BUFFER)) != -1){                   bos.write(data, 0, count);               }               bos.flush();               bos.close();               bis.close();           }           zipFile.close();         }       public static void main(String [] args) throws Exception{           String from="e:\\jdbc.zip";           String to="e:\\aaa\\";           unZip1(from,to);       }       public static void unZip1(String from,String to)throws Exception{           //String from="e:\\aaa.zip";           //String to="E:\\aaa\\";           if(!new File(to).exists()){               new File(to).mkdir();           }           ZipFile file=new ZipFile(from);           Enumeration e=file.entries();           int byte_read;           byte [] buffer=new byte[4096];           while(e.hasMoreElements()){               ZipEntry entry=(ZipEntry)e.nextElement();               if(entry.isDirectory()){                   //String filename=entry.getName();                   new File(to+entry.getName()).mkdirs();                   continue;               }               DataInputStream ois=new DataInputStream(file.getInputStream(entry));               File f=new File(to+entry.getName());               FileOutputStream fos=new FileOutputStream(f);               ObjectOutputStream oos=new ObjectOutputStream(fos);               while((byte_read=ois.read(buffer))!=-1){                   oos.write(buffer,0,byte_read);               }               oos.flush();               oos.close();               ois.close();           }                  }   }  


上一篇: jsp 实现在线人数统计
下一篇: Ajax 从XML到生成表格
关于我们 | 代理申请 | 付款方式 | 客户管理 | 友情链接 | 网站导航
版权所有 2008 三易网络(洛阳)科技开发有限公司
服务热线:0379-63921200   63265368(洛阳) 0371-63653120(郑州)
QQ在线客服: 312236232  516731113   Email:web@suneasy.cn

总部地址:纱厂南路41号中泰新城泰华苑12楼B座 郑州分公司地址:金水区圣菲城