zoukankan      html  css  js  c++  java
  • java zip解压

    /**
    * 解压文件到指定目录
    * @param zipFile
    * @param descDir
    * @author sqdll
    */
    @SuppressWarnings("rawtypes")
    public static void unZipFiles(File zipFile,String descDir)throws IOException {
    File pathFile = new File(descDir);
    if (!pathFile.exists()) {
    pathFile.mkdirs();
    }
    //相关变量
    ZipEntry entry = null;
    InputStream in = null;
    OutputStream out = null;
    String outPath = null;
    File file = null;
    ZipFile zip = new ZipFile(zipFile, Charset.forName("GBK")); //待解压文件
    for (Enumeration entries = zip.entries(); entries.hasMoreElements(); ) {
    entry = (ZipEntry) entries.nextElement();
    in = zip.getInputStream(entry);
    outPath = (descDir + entry.getName()).replaceAll("\*", "/");
    //判断路径是否存在,不存在则创建文件路径
    file = new File(outPath.substring(0, outPath.lastIndexOf('/')));
    if (!file.exists()) {
    file.mkdirs();
    }
    //判断文件全路径是否为文件夹,如果是上面已经上传,不需要解压
    if (new File(outPath).isDirectory()) {
    continue;
    }
    //输出文件路径信息
    System.out.println(outPath);
    out = new FileOutputStream(outPath);
    byte[] buf1 = new byte[1024];
    int len;
    while ((len = in.read(buf1)) > 0) {
    out.write(buf1, 0, len);
    }
    in.close();
    out.close();
    }
    System.out.println("******************解压完毕********************");
    }
  • 相关阅读:
    collections模块整理
    jQuery 事件
    前端开发问题点
    无线wifi
    MySQL 数据库--SQL语句优化
    MySQL 数据库--索引原理与慢查询优化
    MySQL 数据库--内置功能
    MySQL 数据库--权限管理
    MySQL -Naivacat工具与pymysql模块
    MySQL 数据库 -- 数据操作
  • 原文地址:https://www.cnblogs.com/nsw2018/p/6251976.html
Copyright © 2011-2022 走看看