C# BinaryReader.ReadString()方法如何确定从数据流中读多少内容
使用C#的读文件操作代码如下:
using (FileStream input = File.OpenRead("binarydata.dat"))
using (BinaryReader reader = new BinaryReader(input))
{
int intRead = reader.ReadInt32();
byte[] byteRead = reader.ReadBytes(4);
string stringRead = reader.ReadString();
char charRead = reader.ReadChar();
}
其中的ReadString()方法并没有参数告诉它字符串内有多少个字符,它是怎么自动判断的呢?
查阅了MSDN帮助,里面这个方法的说明是这样的
从当前流中读取一个字符串。字符串有长度前缀,一次 7 位地被编码为整数。
说字符串有长度前缀,没没见到这个前缀啊?请大神指导
Circle_Face
2015/05/27 02:16- c#
- ead tring
- 点赞
- 收藏
- 回答
满意答案