ackage org.fh.util;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.util.zip.ZipEntry;
import java.util.zip.ZipOutputStream;
/**
* 说明:java压缩成zip
* 作者:FH Admin
* from:fhadmin.cn
*/
public class FileZip {
/**
* @param inputFileName 你要压缩的文件夹(整个完整路径)
* @param zipFileName 压缩后的文件(整个完整路径)
* @throws Exception
*/
public static Boolean zip(String inputFileName, String zipFileName) throws Exception {
zip(zipFileName, new File(inputFileName));
return true;
}
private static void zip(String zipFileName, File inputFile) throws Exception {
ZipOutputStream out = new ZipOutputStream(new FileOutputStream(zipFileName));
zip(out, inputFile, "");
out.flush();
out.close();
}
private static void zip(ZipOutputStream out, File f, String base) throws Exception {
if (f.isDirectory()) {
File[] fl = f.listFiles();
out.putNextEntry(new ZipEntry(base + "
java 生成 zip格式 压缩文件
最新推荐文章于 2024-09-10 20:28:11 发布