文件夹压缩成.zip格式

来源:互联网 发布:只有我知3小时14分超清 编辑:程序博客网 时间:2024/06/06 04:28

压缩:需要用到   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();            }


0 0
原创粉丝点击