import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.List;
import java.util.zip.GZIPOutputStream;
import org.apache.commons.compress.archivers.tar.TarArchiveEntry;
import org.apache.commons.compress.archivers.tar.TarArchiveOutputStream;
import org.apache.commons.compress.utils.IOUtils;
public class targz {
public static File pack(List<File> sources, File target) throws IOException {
FileOutputStream out = null;
try {
out = new FileOutputStream(target);
} catch (FileNotFoundException e1) {
e1.printStackTrace();
}
TarArchiveOutputStream os = new TarArchiveOutputStream(out);
for (File file : sources) {
InputStream inputStream = null;
try {
os.putArchiveEntry(new TarArchiveEntry(file,file.getName()));
inputStream = new FileInputStream(file);
IOUti
Java 打包文件为tar.gz格式的方法
最新推荐文章于 2024-08-02 09:37:37 发布
本文介绍了如何在Java中将文件打包为tar.gz格式,特别适用于接口自动化中上传日志的需求,通过执行特定代码可生成tar.gz压缩文件。
摘要由CSDN通过智能技术生成