apache commons 压缩的焦油问题 [英] Tar problem with apache commons compress

查看:24
本文介绍了apache commons 压缩的焦油问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在尝试使用压缩库对某些文件进行 tar 处理时遇到了困难.

I'm having a hard time trying to tar some files using the compress library.

我的代码如下,取自commons.compress wiki示例:

My code is the following, and is taken from the commons.compress wiki exemples :

    private static File createTarFile(String[] filePaths, String saveAs) throws Exception{

    File tarFile = new File(saveAs);
    OutputStream out = new FileOutputStream(tarFile);

    TarArchiveOutputStream aos = (TarArchiveOutputStream) new ArchiveStreamFactory().createArchiveOutputStream("tar", out);

    for(String filePath : filePaths){
        File file = new File(filePath);
        TarArchiveEntry entry = new TarArchiveEntry(file);
        entry.setSize(file.length());
        aos.putArchiveEntry(entry);
        IOUtils.copy(new FileInputStream(file), aos);
        aos.closeArchiveEntry();
    }
    aos.finish();
    out.close();


    return tarFile;
}

过程中没有错误,但是当我尝试解压缩文件时,我得到以下信息:

There is no error during the process, but when I try to untar the file, I got the following :

XXXX:XXXX /home/XXXX$ tar -xf typeCommandes.tar
tar: Unexpected EOF in archive
tar: Unexpected EOF in archive
tar: Error is not recoverable: exiting now

此外,存档比原始文件的大小略小,这对于 tar 来说是不正常的,因此确实存在问题...

Also, the archive IS slighty smaller in size than the original file, which isnt normal for a tar, so there DO is a problem...

-rw-r--r--  1 XXXX nobody 12902400 Jan 14 17:11 typeCommandes.tar
-rw-r--r--  1 XXXX nobody 12901888 Jan 14 17:16 typeCommandes.csv

谁能告诉我我做错了什么?谢谢

Anyone can tell me what I'm doing wrong ? Thanks

推荐答案

您没有关闭 TarArchiveOutputStream.在aos.finish()

这篇关于apache commons 压缩的焦油问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆