需要導(dǎo)入ant.jar包,apache網(wǎng)站(http://ant.apache.org/bindownload.cgi)下載即可。
import org.apache.tools.ant.Project;
import org.apache.tools.ant.taskdefs.Expand;
import org.apache.tools.zip.ZipEntry;
import com.xyq.io.util.CloseIoUtil;
public class ZipUtil {
private static final String ENCODE = "UTF-8";
public static void zip(String inputFilePath, String zipFileName) {
File inputFile = new File(inputFilePath);
if (!inputFile.exists())
throw new RuntimeException("原始文件不存在!!!");
File basetarZipFile = new File(zipFileName).getParentFile();
if (!basetarZipFile.exists() && !basetarZipFile.mkdirs())
throw new RuntimeException("目標文件無法創(chuàng)建!!!");
BufferedOutputStream bos = null;
FileOutputStream out = null;
ZipOutputStream zOut = null;
try {
// 創(chuàng)建文件輸出對象out,提示:注意中文支持
out = new FileOutputStream(new String(zipFileName.getBytes(ENCODE)));
bos = new BufferedOutputStream(out);
//
主站蜘蛛池模板:
南陵县|
南溪县|
奉化市|
涟源市|
高雄市|
偃师市|
名山县|
兰州市|
防城港市|
鹿邑县|
邻水|
黑龙江省|
正蓝旗|
宝鸡市|
汪清县|
图片|
邵阳市|
沐川县|
嘉义市|
黔东|
包头市|
宜丰县|
阳东县|
山东省|
犍为县|
北碚区|
澜沧|
界首市|
聊城市|
通许县|
义乌市|
北辰区|
左贡县|
海宁市|
铁岭县|
白玉县|
利川市|
巨野县|
乌恰县|
民丰县|
民丰县|