不是说“Peek 不会更改 StreamReader 的当前位置”么。MS骗人的!

在MSDN里面看到关于StreamReader.Peek 方法的解释,备注里面说
Peek 不会更改 StreamReader 的当前位置。如果当前没有更多的可用字符,则返回值为 -1。

但是假设C:\CMSG.LOG文件一行内容超过1024字节后,运行下面的程序就会发现Peek之后,
Position变成了1024了。但是此后如果再运行Peek就没有问题了,Position不会改变。
难道MSDN说的是错的???

代码:
        Dim fs As New IO.FileStream("C:\CMSG.LOG", IO.FileMode.Open, IO.FileAccess.Read)
        Dim sr As New IO.StreamReader(fs, System.Text.Encoding.GetEncoding(System.Globalization.CultureInfo.CurrentCulture.TextInfo.ANSICodePage))
        MsgBox("Position before peek: " & sr.BaseStream.Position)
        sr.Peek()
        MsgBox("Position after peek: " & sr.BaseStream.Position)
        sr.Close()
        fs.Close()

To dudu:这个问题我在CSDN上面问了,但是没有人回。暂借首页问一下。

posted @ 2005-09-27 09:42  妖居  阅读(1579)  评论(5编辑  收藏  举报