| 12345678910111213141516171819202122232425262728293031323334353637383940 |
- package cn.com.lzt.common.excel;
- import java.io.File;
- import org.apache.tools.ant.Project;
- import org.apache.tools.ant.taskdefs.Zip;
- import org.apache.tools.ant.types.FileSet;
- /**
- * ClassName: ZipCompressorByAnt
- * @Description: TODO
- * @author
- */
- public class ZipCompressorByAnt {
- private File zipFile;
-
- public ZipCompressorByAnt(String pathName) {
- zipFile = new File(pathName);
- }
-
- public int compress(String srcPathName) {
- int result = 0;
- File srcdir = new File(srcPathName);
- if (!srcdir.exists()){
- result = 1;
- throw new RuntimeException(srcPathName + "不存在");
- }
- Project prj = new Project();
- Zip zip = new Zip();
- zip.setProject(prj);
- zip.setDestFile(zipFile);
- //zip.setLevel(0);
- FileSet fileSet = new FileSet();
- fileSet.setProject(prj);
- fileSet.setDir(srcdir);
- zip.addFileset(fileSet);
- zip.execute();
- return result;
- }
- }
|