0

我需要一种从FileStream每个字符中读取的方法。逐个字符。每次我读取一个字符时,我都需要增加FileStream.Position.

我正在尝试代码片段,但它返回多个字符:

Dim bytes(1) As Byte

Dim nBytes As Integer = oFile.Read(bytes, 0, bytes.Length)
Dim nChars As Integer = decoder8.GetCharCount(bytes, 0, nBytes)
Dim chars(nChars - 1) As Char
nChars = decoder8.GetChars(bytes, 0, nBytes, chars, 0)
Return New String(chars, 0, nChars)
4

2 回答 2

0

您可以使用 aStreamReader和它的Read方法,不是吗?

Using rd = New StreamReader("path", Encoding.UTF8)
    While rd.Peek() >= 0
        Dim c As Char = Chr(rd.Read())
        Console.WriteLine("Next character: " & c)
    End While
End Using

StreamReader.Read

从输入流中读取下一个字符并将字符位置前移一个字符。

于 2013-11-13T11:55:31.643 回答
0

假设那oFile是类型FileStream然后

Dim nBytes As Integer = oFile.ReadByte()

应该管用。

于 2013-11-13T15:42:20.833 回答