100 bytes) TarArchiveOutputStream"-6ren"> 100 bytes) TarArchiveOutputStream"-当我压缩一个文件时,它抛出异常“太长(> 100 字节)TarArchiveOutputStream”。请指导我插入 setLongFileMode(TarOutputStream.LONGFILE_-6ren">
gpt4 book ai didi

java - 当我 tar 一个文件时,它的抛出异常为 "is too long ( > 100 bytes) TarArchiveOutputStream"

转载 作者:塔克拉玛干 更新时间:2023-11-02 08:08:21 26 4
gpt4 key购买 nike

当我压缩一个文件时,它抛出异常“太长(> 100 字节)TarArchiveOutputStream”。请指导我插入 setLongFileMode(TarOutputStream.LONGFILE_GNU);在这个程序中。

 private static void zipFilesRecursively(File baseDir, File source,TarArchiveOutputStream out) throws IOException {

if (source.isFile()) {

System.out.println("Adding File: "+ baseDir.toURI().relativize(source.toURI()).getPath());

FileInputStream fi = new FileInputStream(source);

BufferedInputStream sourceStream = new BufferedInputStream(fi,BUFFER);

TarArchiveEntry entry = new TarArchiveEntry(source, baseDir.getParentFile().toURI().relativize(source.toURI()).getPath());

int count;

byte data[] = new byte[BUFFER];

while ((count = sourceStream.read(data, 0, BUFFER)) != -1) {

out.write(data, 0, count);

}

sourceStream.close();

out.closeArchiveEntry();

} else {

if (source.listFiles() != null) {
if (source.listFiles().length == 0) {

System.out.println("Adding Empty Folder: "+ baseDir.toURI().relativize(source.toURI()).getPath());

TarArchiveEntry entry = new TarArchiveEntry(source, baseDir.getParentFile().toURI().relativize(source.toURI()).getPath());
out.putArchiveEntry(entry);
out.closeArchiveEntry();
}

for (File file : source.listFiles())

zipFilesRecursively(baseDir, file, out);

最佳答案

看看这个:http://commons.apache.org/proper/commons-compress/tar.html#Long_File_Names

在使用流之前需要将格式设置为posix:

TarArchiveOutputStream stream = new TarArchiveOutputStream(...)
stream.setLongFileMode(TarArchiveOutputStream.LONGFILE_POSIX)

关于java - 当我 tar 一个文件时,它的抛出异常为 "is too long ( > 100 bytes) TarArchiveOutputStream",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32528799/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com