【问题标题】:How to add a file in a zip using SharpZibLib in c#如何在 c# 中使用 SharpZibLib 在 zip 中添加文件
【发布时间】:2012-03-21 11:05:52
【问题描述】:

我正在尝试使用 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();
        }
    }

谁能告诉我上面的代码有什么问题?为什么 zip 会被过度使用

【问题讨论】:

标签: c# .net sharpziplib


【解决方案1】:

看看这里:

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

你需要打电话

zipFile.BeginUpdate();

//add file..

zipFile.CommitUpdate();

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-03-04
    • 2013-12-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-07-27
    • 2020-09-03
    相关资源
    最近更新 更多