用的是apache的工具包:commons-compress
写入文件名长度超过100时报异常
// 具体可参考官方文档: http://commons.apache.org/proper/commons-compress/tar.html#Long_File_Names
tarArchiveOutputStream.setLongFileMode(TarArchiveOutputStream.LONGFILE_POSIX);
写入文件报异常
java.io.IOException: Request to write '388' bytes exceeds size in header of '0' bytes for entry 'xxx/xxx'
at org.apache.commons.compress.archivers.tar.TarArchiveOutputStream.write(TarArchiveOutputStream.java:449)
at org.apache.commons.io.IOUtils.copyLarge(IOUtils.java:2315)
at org.apache.commons.io.IOUtils.copy(IOUtils.java:2270)
at org.apache.commons.io.IOUtils.copyLarge(IOUtils.java:2291)
at org.apache.commons.io.IOUtils.copy(IOUtils.java:2246)
...
原因是写文件未指定文件大小,需要指定文件大小
TarArchiveEntry tarArchiveEntry = new TarArchiveEntry(filePath);
// 指定文件的大小
tarArchiveEntry.setSize(file.length());
打包tar文件后,在linux系统解压出来后,查看文件报权限不足
在写入文件时修改文件权限
tarArchiveEntry.setMode(tarArchiveEntry.getMode() | 755);