Zip文件解压

/*
 * 功能: 文件解压
 * 用法: java ExtractZipFile zipfile DestinationPath
 * 注意: 不能建立子目录
 */

import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.zip.ZipEntry;
import java.util.zip.ZipInputStream;

public class ExtractZipFile {
 public int scan(String filename) {
  ZipEntry entry = null;
  int filecount = 0;

  try {
   ZipInputStream zin = new ZipInputStream(new FileInputStream(
     filename));
   System.out.println("开始扫描 " + filename + ":");
   System.out.println("-------------------------");
   while ((entry = zin.getNextEntry()) != null) {
    if (entry.isDirectory() || entry.getName().equals("..//")) {
     continue;
    }
    System.out.println(entry.getName());
    filecount++;
    zin.closeEntry();
   }
   zin.close();
   return filecount;
  } catch (IOException e) {
   System.out.println(e);
   return -1;
  }
 }

 public static void main(String[] args) throws Exception {
  if (args.length != 2) {
   System.out.println("*******************************************");
   System.out.println("*    用法: java zip/jar 文件 目标路径         *");
   System.out.println("* Usage: java zip/jarFile DestinationPath *");
   System.out.println("*******************************************");
   System.exit(-1);
  }
  // First Scan the Zip File
  ScanZipFile scanzipfile = new ScanZipFile();
  if (scanzipfile.scan(args[0]) < 0) {
   System.out.println("Unzip Failed! Exiting now...");
   System.exit(-1);
  } else {
   System.out.println("*******************************************");
   System.out
     .println("* Enter Y or y to extract the files, Any other key to exit! *");
   System.out.println("*******************************************");

   String inputString = "";
   byte[] buffer = new byte[255];
   try {
    System.in.read(buffer, 0, 255);
    inputString = new String(buffer);

   } catch (IOException ex) {
    System.out.println(ex);
   }
   if (inputString.indexOf("Y") != -1
     || inputString.indexOf("y") != -1) {
    try {
     ZipInputStream zin = new ZipInputStream(
       new FileInputStream(args[0]));
     ZipEntry entry;
     System.out.println("Now Extracting the " + args[0] + ":");
     String filename;
     while ((entry = zin.getNextEntry()) != null) {
      if (entry.isDirectory()
        || entry.getName().equals("..//")) {
       continue;
      }
      System.out.println(entry.getName());
      filename = args[1] + "//" + entry.getName();
      byte[] buf = new byte[1];
      BufferedInputStream bin = new BufferedInputStream(zin);
      FileOutputStream tfos = new FileOutputStream(filename);
      BufferedOutputStream bout = new BufferedOutputStream(
        tfos);
      while (bin.read(buf, 0, 1) != -1) {
       bout.write(buf, 0, 1);
      }
      bout.close();
      zin.closeEntry();
     }
     zin.close();
     System.out
       .println("*******************************************");
     System.out
       .println("*    Extract Over                    ******");
     System.out
       .println("*******************************************");
    } catch (IOException e) {
     System.out.println(e);
    }
   } else {
    System.out
      .println("*******************************************");
    System.out
      .println("*    Extract Quit                    ******");
    System.out
      .println("*******************************************");

    System.exit(0);
   }
  }
 }
 /*
  * 这个程序接收2个参数, 前一个参数表示要解压的 zip 文件, 后一个参数表示将文件解压到那个指定 目录下.它首先建立一个 ScanZipFile
  * 对象, 然后执行这个对象上的 scan 方法, 将这个压缩文件 中的内容都显示到控制台上, 然后, 它试图从控制台得到一个指令,
  * 用于指明是否对该压缩文件进行解压, 输入 y 或 Y, 将会开始执行解压操作,否则, 将退出整个应用.
  */
}
 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
kangle web服务器( 简称:kangle ) 是一款跨平台、功能强大、安全稳定、易操作的高性能web服务器和反向代理服务器软件。 除此:kangle也是一款专为做虚拟主机研发的web服务器。实现虚拟主机独立进程、独立身份运行。用户之间安全隔离,一个用户出问题不影响其他用户。安全支持php、asp、asp.net、java、ruby等多种动态开发语言。 kangle web服务器主要特点: 1、免费开源 kangle技术团队希望国人拥有一款真正好用、易用、实用的国产web服务器。 2、跨平台 可在linux、windows、freebsd、openbsd、netbsd、solaris等平台上运行。 3、可轻松查看到被攻击的url 这是kangle web服务器独有的,其它web服务器很难查找到。 4、性能高 工作模型多样化。Windows上采用iocp、Linux上采用epoll、Bsd上采用kqueue。 5、功能强大、灵活 kangle的访问控制理念来自linux的iptables防火墙,kangle拥有功能最小化的匹配模块和标记模块,通过组合,反转等可以实现用户最复杂的需求; 谈kangle的访问控制:点击查看 6、是一款做idc的专业web服务器 .实现虚拟主机独立身份,独立进程。 .隔离攻击(实现某个虚拟主机受到外部攻击,不影响到服务器上其它虚拟主机)。 .智能防cc攻击(CC是http协议的攻击,不是tcp/ip,kangle是底层的web服务器,更懂http)。 .做全能空间(php虚拟主机、java虚拟主机等) 2013-08-21 kangle 3.2.3 *修复linux下ssl超连接数引发崩溃的bug *增加配置文件的content-type kangle web服务器截图:
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值