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("******************解压完毕********************");
    }
  • 相关阅读:
    volatile用法
    static用法
    sizeof用法
    C语言void关键字的深刻含义
    extern用法
    const用法
    attribute用法
    Task的运行过程分析
    Android BroadcastReceiver实例Demo(有序广播的发送)
    旅行-许巍
  • 原文地址:https://www.cnblogs.com/nsw2018/p/6251976.html
Copyright © 2011-2022 走看看