0

单击并查看 NoPointerExcepeion

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

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

所以我想 2 知道我在下面的程序中出了什么问题:

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();
}
4

1 回答 1

0

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

于 2016-11-03T06:47:22.073 回答