簡體   English   中英

在 Java 中使用 LZ4 添加到現有的 .lz4 (zip)

[英]Using LZ4 to Add to an existing .lz4 (zip) in Java

我正在使用以下內容和 LZ4 庫在 java 中進行壓縮。 如果我嘗試在相同的文件名上再次調用此方法,它將用新內容覆蓋而不是附加。 有沒有辦法使用 LZ4 追加? 我只想稍后將另一個文件添加到現有的 zip 存檔中。

public void zipFile(File[] fileToZip, String outputFileName, boolean activeZip)
{
    try (FileOutputStream fos = new FileOutputStream(new File(outputFileName));
            LZ4FrameOutputStream lz4fos = new LZ4FrameOutputStream(fos);)
    {
        for (File a : fileToZip)
        {
            try (FileInputStream fis = new FileInputStream(a))
            {
                byte[] buf = new byte[bufferSizeZip];
                int length;
                while ((length = fis.read(buf)) > 0)
                {
                    lz4fos.write(buf, 0, length);
                }
            }                
        }

    }
    catch (Exception e)
    {
        LOG.error("Zipping file failed ", e);
    }
}

我能弄清楚如何做到這一點的唯一方法是發送

new FileOutputStream(new File(outputFileName),false)

在試用資源中

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM