2012-03-21 32 views
0

我想用cZ中的sharpZibLib將文件添加到現有的zip中。 當運行zip得到qverwrite時,即zip中的所有文件被刪除,並且只有新文件在zip中。如何使用C#中的SharpZibLib在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(); 
     } 
    } 

誰能告訴我什麼是在上面的代碼中的問題?爲什麼拉鍊被overwitten

+1

的[C#sharpziplib添加文件到現有檔案](HTTP可能重複:// stackoverflow.com/questions/1356003/c-sharp-sharpziplib-adding-file-to-existing-archive) – Oded 2012-03-21 11:09:15

回答

相關問題