【问题标题】:Apache Commons Compress: ZipArchiveEntry.getUnixMode() always returns 0Apache Commons Compress:ZipArchiveEntry.getUnixMode() 始终返回 0
【发布时间】:2021-08-16 11:50:08
【问题描述】:

在分析结果文件时,值被正确写入,所以setUnixMode() 可能工作正常,但getUnixMode() 总是返回 0。有人有这方面的经验吗?

File file = new File("Test.file");
ZipArchiveOutputStream zipArchiveOutputStream = new ZipArchiveOutputStream(new FileOutputStream(file));   
ZipArchiveEntry zipArchiveEntry = new ZipArchiveEntry("Entry");  
zipArchiveEntry.setUnixMode(0744);
zipArchiveOutputStream.putArchiveEntry(zipArchiveEntry);
zipArchiveOutputStream.write("TestBytes".getBytes());
zipArchiveOutputStream.closeArchiveEntry();
zipArchiveOutputStream.close();
                        
ZipArchiveInputStream zipArchiveInputStream = new ZipArchiveInputStream(new FileInputStream(file));
ZipArchiveEntry entryOut = zipArchiveInputStream.getNextZipEntry();
System.out.println(entryOut.getUnixMode());

【问题讨论】:

    标签: java apache-commons-compress


    【解决方案1】:

    getUnixMode() 在平台 != PLATFORM_UNIX 时返回 0(源代码参见 here)。所以你还必须指定平台:zipArchiveEntry.setPlatform(ZipArchiveEntry.PLATFORM_UNIX)

    【讨论】:

    • 还是零:(.
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2018-12-10
    • 1970-01-01
    • 1970-01-01
    • 2017-09-05
    • 2019-03-16
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多