【背景】

近日在研究web邮件下载功能,下载的邮件能够导入foxmail邮件client。可是批量下载邮件还需将邮件打成一个压缩包。

从网上搜索通过java实现文件压缩、解压缩有非常多现成的样例。

【參考代码】(须要下载apache ant.jar包)

import java.io.File;

import org.apache.tools.ant.BuildException;
import org.apache.tools.ant.Project;
import org.apache.tools.ant.taskdefs.Expand;
import org.apache.tools.ant.taskdefs.Zip;
import org.apache.tools.ant.types.FileSet; public class Zipper {
public final static String encoding = "GBK"; // 压缩
public static void zip(String srcPathname, String zipFilepath)
throws BuildException, RuntimeException {
File file = new File(srcPathname);
if (!file.exists())
throw new RuntimeException("source file or directory "
+ srcPathname + " does not exist."); Project proj = new Project();
FileSet fileSet = new FileSet();
fileSet.setProject(proj);
// 推断是文件夹还是文件
if (file.isDirectory()) {
fileSet.setDir(file);
// ant中include/exclude规则在此都能够使用
// 比方:
// fileSet.setExcludes("**/*.txt");
// fileSet.setIncludes("**/*.xls");
} else {
fileSet.setFile(file);
} Zip zip = new Zip();
zip.setProject(proj);
zip.setDestFile(new File(zipFilepath));
zip.addFileset(fileSet);
zip.setEncoding(encoding);
zip.execute();
} // 解压缩
public static void unzip(String zipFilepath, String destDir)
throws BuildException, RuntimeException {
if (!new File(zipFilepath).exists())
throw new RuntimeException("zip file " + zipFilepath
+ " does not exist."); Project proj = new Project();
Expand expand = new Expand();
expand.setProject(proj);
expand.setTaskType("unzip");
expand.setTaskName("unzip");
expand.setEncoding(encoding); expand.setSrc(new File(zipFilepath));
expand.setDest(new File(destDir));
expand.execute();
}
}

java代理使用 apache ant实现文件压缩/解压缩的更多相关文章

  1. 使用 apache ant 轻松实现文件压缩/解压缩(转)

    原文地址:http://blog.csdn.net/irvine007/article/details/6779492 maven配置ant包: <dependency> <grou ...

  2. Java实现对zip和rar文件的解压缩

    通过java实现对zip和rar文件的解压缩

  3. ubuntu下文件压缩/解压缩

    ubuntu下文件压缩/解压缩 http://blog.csdn.net/luo86106/article/details/6946255 .gz 解压1:gunzip FileName.gz 解压2 ...

  4. 前端部署ant+yuicompressor文件压缩+获取版本+SSH公布(部分代码)

    文件压缩: <apply executable="java" parallel="false" failonerror="true" ...

  5. AntZipUtils【基于Ant的Zip压缩解压缩工具类】

    版权声明:本文为HaiyuKing原创文章,转载请注明出处! 前言 Android 压缩解压zip文件一般分为两种方式: 基于JDK的Zip压缩工具类 该版本存在问题:压缩时如果目录或文件名含有中文, ...

  6. ubuntu下文件压缩/解压缩命令总结

    .gz 解压1:gunzip FileName.gz 解压2:gzip -d FileName.gz 压缩:gzip FileName .tar.gz 解压:tar zxvf FileName.tar ...

  7. Shell命令-文件压缩解压缩之tar、unzip

    文件及内容处理 - tar.unip 1.tar:打包压缩命令 tar命令的功能说明 tar 命令常用语用于备份文件,tar 是用来建立,还原备份文件的工具程序,它可以加入,解开备份文件内的文件 ta ...

  8. Shell命令-文件压缩解压缩之gzip、zip

    文件及内容处理 - gzip.zip 1.gzip:gzip压缩工具 gzip命令的功能说明 gzip 命令用于压缩文件.gzip 是个使用广泛的压缩程序,文件经它压缩过后,其名称后面会多出 .gz ...

  9. Android zip文件压缩解压缩

    DirTraversal.java <P style="TEXT-ALIGN: left; PADDING-BOTTOM: 0px; WIDOWS: 2; TEXT-TRANSFORM ...

随机推荐

  1. $P2126 Mzc家中的男家丁$

    problem #ifdef Dubug #endif #include <bits/stdc++.h> using namespace std; typedef long long LL ...

  2. BZOJ 3625 多项式求逆+多项式开根

    思路: RT //By SiriusRen #include <bits/stdc++.h> using namespace std; <<,mod=; int A[N],C[ ...

  3. ACM_堆箱子咯(栈)

    堆箱子咯 Time Limit: 2000/1000ms (Java/Others) Problem Description: 双十一大家都在买买买,可忙坏了快递小哥了.zl和皮卡鸡在大伙在剁手的时候 ...

  4. Github提交本地版本是遇到的问题

    问题如下:*** Please tell me who you are. Run git config --global user.email "you@example.com" ...

  5. fastjson读取json配置文件

    fastjson读取json配置文件: ClassLoader loader=FileUtil.class.getClassLoader(); InputStream stream=loader.ge ...

  6. [Windows Server 2008] 手工创建安全网站

    ★ 欢迎来到[护卫神·V课堂],网站地址:http://v.huweishen.com★ 护卫神·V课堂 是护卫神旗下专业提供服务器教学视频的网站,每周更新视频.★ 本节我们将带领大家:手工创建安全站 ...

  7. POJ 3070 - 快速矩阵幂求斐波纳契数列

    这题并不复杂. 设$A=\begin{pmatrix} 1 & 1 \\ 1 & 0 \end{pmatrix}$ 由题中公式: $\begin{pmatrix}f(n+1) & ...

  8. 【sqli-labs】 less58 GET -Challenge -Double Query -5 queries allowed -Variation1 (GET型 挑战 双查询 只允许5次查询 变化1)

    单引号闭合成功,但是union select结果不对 http://192.168.136.128/sqli-labs-master/Less-58/?id=0' union select 1,2,3 ...

  9. (转)OL2中设置鼠标的样式

    http://blog.csdn.net/gisshixisheng/article/details/49496289 概述: 在OL2中,鼠标默认是箭头,地图移动时,鼠标样式是移动样式:很多时候,为 ...

  10. mysql_基础1

    初学mysql,感觉挺有意思的. mysql指令的一些参数: promrt修改提示符:   PROMPT \D mysql的语法规范: 一些函数: 创建数据库: SHOW CREATE DATABAS ...