我正在尝试使用MemoryStream如下的简单演示文本文件创建ZIP存档:using (var memoryStream = new MemoryStream())using (var archive = new ZipArchive(memoryStream , ZipArchiveMode.Create)){ var demoFile = archive.CreateEntry("foo.txt"); using (var entryStream = demoFile.Open()) using (var streamWriter = new StreamWriter(entryStream)) { streamWriter.Write("Bar!"); } using (var fileStream = new FileStream(@"C:\Temp\test.zip", FileMode.Create)) { stream.CopyTo(fileStream); }}如果我运行此代码,则会创建存档文件本身,但不会创建foo.txt。但是,如果我MemoryStream直接替换文件流,则会正确创建存档:using (var fileStream = new FileStream(@"C:\Temp\test.zip", FileMode.Create))using (var archive = new ZipArchive(fileStream, FileMode.Create)){ // ...}是否可以使用a MemoryStream创建ZIP存档而不用FileStream?
3 回答
- 3 回答
- 0 关注
- 1144 浏览
添加回答
举报
0/150
提交
取消