import org.apache.commons.compress.archivers.tar.TarArchiveEntry; import org.apache.commons.compress.archivers.tar.TarArchiveOutputStream; import org.apache.commons.compress.utils.IOUtils; import org.apache.tools.tar.TarEntry; import org.apache.tools.tar.TarInputStream; import java.io.*; import java.util.zip.GZIPInputStream; import java.util.zip.GZIPOutputStream; /** * @Title: GZIPUtil.java * @Description: gzip file compression and decompression tool classes * @author zp * @date * @version V1.0 */ public class GZIPUtil { //in order to gzip file to tar.gz,we need to get *.tar file /** * * @Title: pack * @Description: Copy a set of files into tar packages * @param sources An array of original files to be packed * @param target Define the file after the tar package * @return File return the tar file * @throws */ public static File pack(File[] sources, File target){ FileOutputStream out = null; try { out = new FileOutputStream(target); } catch (FileNotFoundException e1) { e1.printStackTrace(); } TarArchiveOutputStream os = new TarArchiveOutputStream(out); for (File file : sources) { try { os.putArchiveEntry(new TarArchiveEntry(file)); IOUtils.cop
Java 实现*.tar.gz文件压缩和解压
最新推荐文章于 2024-05-22 19:45:58 发布