需要Apache Commons :
commons-compress-1.12.jar
commons-io-2.5.jar
/**
* 解压zip,解压jar,解压到当前文件夹下 * @param zipFilePath zip或jar文件完整路径 * @throws IOException */ public static void uncompressZip(String zipFilePath) throws IOException{ File file = new File(zipFilePath); String fileName = null; if (file.isFile() && (file.getName().endsWith(".zip") || file.getName().endsWith(".jar"))) { fileName = zipFilePath.substring(0,zipFilePath.lastIndexOf(".")); ZipFile zipFile = new ZipFile(zipFilePath); Enumeration<ZipArchiveEntry> en = zipFile.getEntries(); ZipArchiveEntry ze; while (en.hasMoreElements()) { ze = en.nextElement(); File f = new File(fileName, ze.getName()); // 创建完整路径 if (ze.isDirectory()) { f.mkdirs(); continue; } else f.getParentFile().mkdirs(); InputStream is = zipFile.getInputStream(ze); OutputStream os = new FileOutputStream(f); IOUtils.copy(is, os, 4096); is.close(); os.close(); } zipFile.close(); } }