利用ant进行zip解压,非常简单
import org.apache.tools.ant.Project; import org.apache.tools.ant.taskdefs.Expand; public void testUnZip() { String unZipFile = "F:/OMSInstall201108150953_windows_release/packages/sso.zip"; String saveZipFilePath = "D:/testzip"; File srcdir = new File(unZipFile); if (!srcdir.exists()) { System.out.println("The '" + unZipFile + "' file ile does not exist."); return; } File saveZipFile = new File(saveZipFilePath); if (!saveZipFile.exists()) { saveZipFile.mkdirs(); } Project prj1 = new Project(); Expand expand = new Expand(); expand.setProject(prj1); expand.setSrc(new File(unZipFile)); expand.setOverwrite(true);// 是否覆盖 File f = new File(saveZipFilePath); expand.setDest(f); expand.execute(); } public void testzip() { String zipFilePath= "D:/testzip"; String saveZipFilePath = "D:/sso.zip"; File srcdir = new File(zipFilePath); if (!srcdir.exists()) { return; } File zipFile = new File(saveZipFilePath); Project prj = new Project(); Zip zip = new Zip(); zip.setProject(prj); zip.setDestFile(zipFile); FileSet fileSet = new FileSet(); fileSet.setProject(prj); fileSet.setDir(srcdir); zip.addFileset(fileSet); zip.execute(); }