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("******************解压完毕********************");
    }
  • 相关阅读:
    php获取文件后缀名格式
    猴子分桃问题2
    猴子吃桃问题1
    判断字符串中字母出现的次数用分割法
    成绩表
    二维数组所有元素求和输出
    冒泡排序
    1.8作业
    1.8
    1.6
  • 原文地址:https://www.cnblogs.com/nsw2018/p/6251976.html
Copyright © 2011-2022 走看看