我正在使用以下代码:
var fileStream = new MemoryStream();
var binaryWriter = new BinaryWriter(fileStream);
var binaryReader = new BinaryReader(fileStream);
binaryWriter.Write("Hello");
var msg = binaryReader.ReadString();
但是我收到以下异常:
System.IO.EndOfStreamException: Unable to read beyond the end of the stream.
在读取之前,binaryReader.BaseStream.Length
大于 0,但binaryReader.PeekChar()
返回 -1。
我究竟做错了什么?