首页

通过java.util.zip.*对java的sources源码jar包和javadoc文档zip包进行打印解压demo代码示例

标签:jar源码解压,ZipEntry,ZipFile,javadoc的zip压缩包,解压代码demo     发布时间:2021-02-11   

通过java.util.zip.* api实现对ejabberd-external-auth-java-1.0.0-javadoc.zip 文档zip包和ejabberd-external-auth-java-1.0.0-sources.jar源码包分别进行解压打印测试,详情见代码

package com.xwood.demo.main.zip;@b@@b@import java.io.*;@b@import java.nio.charset.Charset;@b@import java.util.Enumeration;@b@import java.util.zip.ZipEntry;@b@import java.util.zip.ZipFile;@b@@b@public class UZipFile{@b@	@b@  /**@b@   * 解压到指定目录@b@   */@b@  public static void unZipFiles(String zipPath,String descDir)throws IOException{@b@    unZipFiles(new File(zipPath), descDir);@b@  }@b@  @b@  /**@b@   * 解压文件到指定目录@b@   */@b@  @SuppressWarnings("rawtypes")@b@  public static void unZipFiles(File zipFile,String descDir)throws IOException@b@  {@b@    File pathFile = new File(descDir);@b@    if(!pathFile.exists())@b@    {@b@      pathFile.mkdirs();@b@    }@b@    //解决zip文件中有中文目录或者中文文件@b@    ZipFile zip = new ZipFile(zipFile, Charset.forName("GBK"));@b@    for(Enumeration entries = zip.entries(); entries.hasMoreElements();){@b@      ZipEntry entry = (ZipEntry)entries.nextElement();@b@      String zipEntryName = entry.getName();@b@      InputStream in = zip.getInputStream(entry);@b@      String outPath = (descDir+zipEntryName).replaceAll("\\*", "/");;@b@      //判断路径是否存在,不存在则创建文件路径@b@      File file = new File(outPath.substring(0, outPath.lastIndexOf('/')));@b@      if(!file.exists())@b@      {@b@        file.mkdirs();@b@      }@b@      //判断文件全路径是否为文件夹,如果是上面已经上传,不需要解压@b@      if(new File(outPath).isDirectory())@b@      {@b@        continue;@b@      }@b@      //输出文件路径信息@b@      System.out.println(outPath);@b@      OutputStream out = new FileOutputStream(outPath);@b@      byte[] buf1 = new byte[1024];@b@      int len;@b@      while((len=in.read(buf1))>0){@b@        out.write(buf1,0,len);@b@      }@b@      in.close();@b@      out.close();@b@    }@b@    System.out.println("******************解压完毕********************");@b@  }@b@  @b@  @b@  public static void main(String[] args) throws IOException {@b@	  //解压javadoc zip压缩包@b@    File zipFile = new File("C:/test/ejabberd-external-auth-java-1.0.0-javadoc.zip");@b@    String path = "C:/test/out/";@b@    unZipFiles(zipFile, path);@b@    @b@    //解压source源码 zip压缩包@b@    zipFile = new File("C:/test/ejabberd-external-auth-java-1.0.0-sources.jar");@b@    path = "C:/test/sourceOut/";@b@    unZipFiles(zipFile, path);@b@  }@b@  @b@}

控制台结果

C:/test/out/META-INF/MANIFEST.MF@b@C:/test/out/ae/teletronics/Application.html@b@C:/test/out/ae/teletronics/class-use/Application.html@b@C:/test/out/ae/teletronics/class-use/CommandType.html@b@C:/test/out/ae/teletronics/class-use/ExternalAuth.html@b@C:/test/out/ae/teletronics/class-use/InputCommand.html@b@C:/test/out/ae/teletronics/class-use/UserManagement.html@b@C:/test/out/ae/teletronics/CommandType.html@b@C:/test/out/ae/teletronics/ExternalAuth.html@b@C:/test/out/ae/teletronics/InputCommand.html@b@C:/test/out/ae/teletronics/package-frame.html@b@C:/test/out/ae/teletronics/package-summary.html@b@C:/test/out/ae/teletronics/package-tree.html@b@C:/test/out/ae/teletronics/package-use.html@b@C:/test/out/ae/teletronics/UserManagement.html@b@C:/test/out/allclasses-frame.html@b@C:/test/out/allclasses-noframe.html@b@C:/test/out/constant-values.html@b@C:/test/out/deprecated-list.html@b@C:/test/out/help-doc.html@b@C:/test/out/index-all.html@b@C:/test/out/index.html@b@C:/test/out/overview-tree.html@b@C:/test/out/package-list@b@C:/test/out/script.js@b@C:/test/out/stylesheet.css@b@******************解压完毕********************@b@C:/test/sourceOut/META-INF/MANIFEST.MF@b@C:/test/sourceOut/ae/teletronics/Application.java@b@C:/test/sourceOut/ae/teletronics/CommandType.java@b@C:/test/sourceOut/ae/teletronics/ExternalAuth.java@b@C:/test/sourceOut/ae/teletronics/InputCommand.java@b@C:/test/sourceOut/ae/teletronics/UserManagement.java@b@******************解压完毕********************