Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/spring-mvc/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Vb.net 从文件流中读取UTF8字符_Vb.net_Filestream_Utf - Fatal编程技术网

Vb.net 从文件流中读取UTF8字符

Vb.net 从文件流中读取UTF8字符,vb.net,filestream,utf,Vb.net,Filestream,Utf,我需要一种从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

我需要一种从
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)

您可以使用
StreamReader
及其方法,不是吗

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

从输入流中读取下一个字符并前进 一个字符的字符位置


假设文件的
类型为
FileStream
,则

Dim nBytes As Integer = oFile.ReadByte()

应该可以工作。

不,我不能,因为FileStream在特定名称空间中使用了多次