将文件解压缩到路径。
//package com.nowjava;/* 来自 时 代 Java 公 众 号 - nowjava.com*/ import java.io.*; import java.util.Enumeration; import java.util.jar.JarEntry; import java.util.jar.JarFile; public class Main { /** * Unzip files to path. * * @param zipFileName the zip file name * @param fileExtractPath the file extract path * @throws IOException Signals that an I/O exception has occurred. */ public static void unzipFilesToPath(String jarPath, String destinationDir) throws IOException { File file = new File(jarPath); JarFile jar = new JarFile(file); /*来自 N o w J a v a . c o m*/ // fist get all directories, // then make those directory on the destination Path for (Enumeration<JarEntry> enums = jar.entries(); enums .hasMoreElements();) { JarEntry entry = (JarEntry) enums.nextElement(); String fileName = destinationDir + File.separator + entry.getName(); File f = new File(fileName); if (fileName.endsWith("/")) { f.mkdirs(); } } //now create all files for (Enumeration<JarEntry> enums = jar.entries(); enums .hasMoreElements();) { JarEntry entry = (JarEntry) enums.nextElement(); String fileName = destinationDir + File.separator + entry.getName(); File f = new File(fileName); if (!fileName.endsWith("/")) { InputStream is = jar.getInputStream(entry); FileOutputStream fos = new FileOutputStream(f