0

我正在尝试使用 c# 中的 sharpZibLib 将文件添加到现有的 zip 中。当运行 zip 得到 qverwrite 即 zip 中的所有文件都被删除并且只有新文件存在于 zip 中。

using (FileStream fileStream = File.Open("D:/Work/Check.zip", FileMode.Open, FileAccess.ReadWrite))
    using (ZipOutputStream zipToWrite = new ZipOutputStream(fileStream))
    {
        zipToWrite.SetLevel(9);

        using (FileStream newFileStream = File.OpenRead("D:/Work/file1.txt"))
        {
            byte[] byteBuffer = new byte[newFileStream.Length - 1];

            newFileStream.Read(byteBuffer, 0, byteBuffer.Length);

            ZipEntry entry = new ZipEntry("file1.txt");
            zipToWrite.PutNextEntry(entry);
            zipToWrite.Write(byteBuffer, 0, byteBuffer.Length);
            zipToWrite.CloseEntry();


            zipToWrite.Finish();
            zipToWrite.Close();
        }
    }

谁能告诉我上面代码中的问题是什么?为什么拉链会被过度使用

4

1 回答 1

1

看看这里:

http://wiki.sharpdevelop.net/SharpZipLib_Updating.ashx

你需要打电话

zipFile.BeginUpdate();

//add file..

zipFile.CommitUpdate();
于 2012-03-21T11:12:23.417 回答