从C#的zip文件中读取二进制文件,而无需将其解压缩
作者:互联网
我想从一个zip文件中读取一个二进制文件而不将其解压缩.
压缩文件结构:
zipFolderName/subFolder/BinFile
在BinFile中,我有:
Id1, id2, value1 // id1, id2 are string, value1 is int
在C#中:
ZipEntry binFileName = …; // it has been got from zipFile entries
MemoryStream ms = new MemoryStream();
binFileName.Extract(ms);
using (BinaryReader reader = new BinaryReader(ms))
{
string id1 = reader.ReadString(); // error popped here
string id2 = reader.ReadString();
int value1 = reader.ReadInt32();
}
我收到错误消息:
无法读到流的末尾.
看来BinaryReader无法读取MemoryStream?
解决方法:
在binFileName.Extract(ms)之后;尝试以下方法:
ms.Seek(0, SeekOrigin.Begin);
标签:binaryreader,zipfile,bin,c,net 来源: https://codeday.me/bug/20191026/1933152.html