需要導(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);
//
主站蜘蛛池模板:
汨罗市|
泰顺县|
库车县|
江阴市|
抚顺县|
临泉县|
海晏县|
安达市|
万州区|
揭阳市|
甘德县|
句容市|
盱眙县|
交口县|
搜索|
石家庄市|
东阳市|
环江|
海淀区|
岳阳市|
黄龙县|
抚州市|
肃南|
湖南省|
台北市|
沙河市|
馆陶县|
全椒县|
明溪县|
梁河县|
彰化县|
阜新|
酒泉市|
宝丰县|
宁国市|
灌云县|
金川县|
丹东市|
丹东市|
台南县|
广汉市|