为什么NoPointerExcepeion在通过apache压缩解压缩时?

时间:2016-11-03 01:39:53

标签: nullpointerexception apache-commons-compress

click and see The NoPointerExcepeion

我生成tar.gz文件并发送2个其他4个解压缩,但是他们的progrem上面有错误(他们的progrem不是由我创建的),只有一个文件有错误。

但是在我的电脑和电脑上使用命令'tar -xzvf ***'时,没有问题......

所以我希望2知道下面的progrem中出了什么问题:

public static void archive(ArrayList<File> files, File destFile) throws Exception {
    TarArchiveOutputStream taos = new TarArchiveOutputStream(new FileOutputStream(destFile));
    taos.setLongFileMode(TarArchiveOutputStream.LONGFILE_POSIX);
    for (File file : files) {
        //LOG.info("file Name: "+file.getName());
        archiveFile(file, taos, "");
    }
}

private static void archiveFile(File file, TarArchiveOutputStream taos, String dir) throws Exception {
    TarArchiveEntry entry = new TarArchiveEntry(dir + file.getName());
    entry.setSize(file.length());
    taos.putArchiveEntry(entry);
    BufferedInputStream bis = new BufferedInputStream(new FileInputStream(file));
    int count;
    byte data[] = new byte[BUFFER];
    while ((count = bis.read(data, 0, BUFFER)) != -1) {
        taos.write(data, 0, count);
    }
    bis.close();
    taos.closeArchiveEntry();
}

1 个答案:

答案 0 :(得分:0)

堆栈跟踪看起来像Apache Commons Compress https://issues.apache.org/jira/browse/COMPRESS-223中的一个错误,已经修复了1.7版本(大约三年前发布)。