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-06-30 15:03:01 发布
GZIPUtil类提供了gzip文件压缩和解压缩工具方法。包括将一组文件打包成.tar文件,然后压缩为.tar.gz文件,以及解压.tar.gz文件到指定目录。主要使用了Apache Commons Compress和Java内置的压缩流进行操作。
摘要由CSDN通过智能技术生成