50,549
社区成员
发帖
与我相关
我的任务
分享
public static File pack(List<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 {
System.out.println(file.getName());
os.putArchiveEntry(new TarArchiveEntry(file));
IOUtils.copy(new FileInputStream(file), os);
os.closeArchiveEntry();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
if (os != null) {
try {
os.flush();
os.close();
} catch (IOException e) {
e.printStackTrace();
}
}
return target;
}
TarArchiveEntry tae = new TarArchiveEntry(file);
tae.setName(file.getName());
os.putArchiveEntry(tae);