将 ZipArchive 保存到文件
Save ZipArchive to file
在我的应用程序中,我有一个 class 使用 System.IO.Compression.ZipArchive
处理 zip 存档。
现在我想将存档的条目保存到文件中。我怎样才能做到这一点?我知道我可以将 Stream
与存档相关联,但在我的情况下,存档会创建 w/o 流,我无法更改代码:
var archive = ZipFile.Open(fileName, ZipArchiveMode.Create);
// add entries
// how can I save it to file now?
你已经是 'saving it to a file',fileName
所指的人了。
要确保所有内容都已写入并刷新,请使用 using
:
using (var archive = ZipFile.Open(fileName, ZipArchiveMode.Create))
{
// add entries
....
} // here it is saved and closed
在我的应用程序中,我有一个 class 使用 System.IO.Compression.ZipArchive
处理 zip 存档。
现在我想将存档的条目保存到文件中。我怎样才能做到这一点?我知道我可以将 Stream
与存档相关联,但在我的情况下,存档会创建 w/o 流,我无法更改代码:
var archive = ZipFile.Open(fileName, ZipArchiveMode.Create);
// add entries
// how can I save it to file now?
你已经是 'saving it to a file',fileName
所指的人了。
要确保所有内容都已写入并刷新,请使用 using
:
using (var archive = ZipFile.Open(fileName, ZipArchiveMode.Create))
{
// add entries
....
} // here it is saved and closed