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("******************解压完毕********************");
    }
  • 相关阅读:
    Java:synchronized关键字引出的多种锁
    Java:Web Service初入门
    Java:HashMap原理与设计缘由
    Java:集合类的数据结构
    NoSQL数据库兴起
    Hadoop介绍与安装
    Java:泛型的理解
    《代码整洁之道》总结和笔记
    shell运算
    shell变量
  • 原文地址:https://www.cnblogs.com/nsw2018/p/6251976.html
Copyright © 2011-2022 走看看