如何将Java中每个ZipArchiveEntry的自定义信息添加到Zip存档中(getComment始终为空)
使用:Java、Apache Commons Compress(1.10) (如何将Java中每个ZipArchiveEntry的自定义信息添加到Zip存档中(getComment始终为空),java,apache,zip,archive,Java,Apache,Zip,Archive,使用:Java、Apache Commons Compress(1.10) (org.apache.commons.compress.archivers.zip.ZipArchiveOutputStream) (org.apache.commons.compress.archivers.zip.ZipArchiveEntry) 有没有办法,如何为ZIP存档条目添加自定义信息(字节[]或字符串) 我尝试使用以下方法: entry.setExtra(byte[] extra); entry.setE
org.apache.commons.compress.archivers.zip.ZipArchiveOutputStream
)
(org.apache.commons.compress.archivers.zip.ZipArchiveEntry
)
有没有办法,如何为ZIP存档条目添加自定义信息(字节[]或字符串)
我尝试使用以下方法:
entry.setExtra(byte[] extra);
entry.setExtraFields(ZipExtraField[] fields);
entry.setComment(String comment);
ZipArchiveOutputStream zaos = new ZipArchiveOutputStream(fos);
ZipArchiveEntry entry = new ZipArchiveEntry(file.getName());
entry.setComment("Test");
zaos.putArchiveEntry(entry);
// write data
zaos.closeArchiveEntry();
zaos.finish();
但似乎setExtra
仅限于2个字节,setExtraFields
只接受ZIP标准化字段,而不接受任何自定义参数
最有希望的setComment
总是null(解压),不管它是在什么地方设置的(压缩)
压缩示例(使用setComment
):
entry.setExtra(byte[] extra);
entry.setExtraFields(ZipExtraField[] fields);
entry.setComment(String comment);
ZipArchiveOutputStream zaos = new ZipArchiveOutputStream(fos);
ZipArchiveEntry entry = new ZipArchiveEntry(file.getName());
entry.setComment("Test");
zaos.putArchiveEntry(entry);
// write data
zaos.closeArchiveEntry();
zaos.finish();
在解压缩时entry.getComment()
为null