我编写了如下方法将多个 Memorystream 绑定到 ziparchive。该代码适用于一个流,但如果我通过迭代添加多个流,则它会在 for 循环的第二行显示以下错误。
System.IO.IOException: 'Entries cannot be created
while previously created entries are still open.'
我的代码,
using (var zip = new ZipArchive(outputStream, ZipArchiveMode.Create,
leaveOpen: false))
{
for (int i = 0; i < msList.Count; i++)
{
msList[i].Position = 0;
var createenter = zip.CreateEntry("123"+i+".jpg",
CompressionLevel.Optimal);
msList[i].CopyTo(createenter.Open());
}
}