压缩:需要用到 org.apache.tools.ant.taskdefs.Zip 相应的包自行下载
/**
* <将文件夹压缩成zip格式>
* <功能详细描述>
* @param sDirPath 待压缩的文件夹
* @param sZipPath 压缩后的zip文件路径
* @see [类、类#方法、类#成员]
*/
private void createZip(String sDirPath, String sZipPath)
{
File zipFile = new File(sZipPath);
File dirFile = new File(sDirPath);
if (!dirFile.exists())
{
throw new RuntimeException(sDirPath + "不存在!");
}
Project prj = new Project();
Zip zip = new Zip();
zip.setProject(prj);
zip.setDestFile(zipFile);
FileSet fileSet = new FileSet();
fileSet.setProject(prj);
fileSet.setDir(dirFile);
//fileSet.setIncludes("**/*.java"); //包括哪些文件或文件夹 eg:zip.setIncludes("*.java");
//fileSet.setExcludes(...); //排除哪些文件或文件夹
zip.addFileset(fileSet);
zip.execute();
}