需要導入ant.jar包,apache網站(http://ant.apache.org/bindownload.cgi)下載即可。
復制代碼 代碼如下:
import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.zip.ZipOutputStream;
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("目標文件無法創建!!!");
BufferedOutputStream bos = null;
FileOutputStream out = null;
ZipOutputStream zOut = null;
try {
// 創建文件輸出對象out,提示:注意中文支持
out = new FileOutputStream(new String(zipFileName.getBytes(ENCODE)));
bos = new BufferedOutputStream(out);
//
主站蜘蛛池模板:
桂林市|
兰考县|
五华县|
金堂县|
井研县|
克山县|
镇远县|
昂仁县|
驻马店市|
峨边|
咸阳市|
武清区|
宾川县|
明溪县|
手游|
兴文县|
吴旗县|
孟津县|
唐山市|
田阳县|
沧源|
昭平县|
丹棱县|
会东县|
曲靖市|
会理县|
芒康县|
新巴尔虎左旗|
彩票|
沾益县|
中牟县|
莲花县|
威宁|
鄱阳县|
昌都县|
民权县|
涪陵区|
平乡县|
淄博市|
宁阳县|
当阳市|