本文整理汇总了VB.NET中System.IO.BinaryReader.ReadByte方法的典型用法代码示例。如果您正苦于以下问题:VB.NET BinaryReader.ReadByte方法的具体用法?VB.NET BinaryReader.ReadByte怎么用?VB.NET BinaryReader.ReadByte使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.IO.BinaryReader
的用法示例。
在下文中一共展示了BinaryReader.ReadByte方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的VB.NET代码示例。
示例1: BinaryRW
' 导入命名空间
Imports System.IO
Public Class BinaryRW
Shared Sub Main()
Dim i As Integer = 0
' Create random data to write to the stream.
Dim writeArray(1000) As Byte
Dim randomGenerator As New Random()
randomGenerator.NextBytes(writeArray)
Dim binWriter As New BinaryWriter(New MemoryStream())
Dim binReader As New BinaryReader(binWriter.BaseStream)
Try
' Write the data to the stream.
Console.WriteLine("Writing the data.")
For i = 0 To writeArray.Length - 1
binWriter.Write(writeArray(i))
Next i
' Set the stream position to the beginning of the stream.
binReader.BaseStream.Position = 0
' Read and verify the data from the stream.
For i = 0 To writeArray.Length - 1
If binReader.ReadByte() <> writeArray(i) Then
Console.WriteLine("Error writing the data.")
Return
End If
Next i
Console.WriteLine("The data was written and verified.")
' Catch the EndOfStreamException and write an error message.
Catch ex As EndOfStreamException
Console.WriteLine("Error writing the data: {0}", _
ex.GetType().Name)
End Try
End Sub
End Class