Imports Microsoft.VisualBasic
Imports System
Imports System.IO
Imports System.Text
Class FStream
Shared Sub Main()
Const fileName As String = "Test.dat"
Dim dataArray(100000) As Byte
Dim randomGenerator As New Random()
randomGenerator.NextBytes(dataArray)
Dim fileStream As FileStream = new FileStream(fileName, FileMode.Create)
Try
For i As Integer = 0 To dataArray.Length - 1
fileStream.WriteByte(dataArray(i))
Next i
fileStream.Seek(0, SeekOrigin.Begin)
For i As Integer = 0 To CType(fileStream.Length, Integer) - 1
If dataArray(i) <> fileStream.ReadByte() Then
Console.WriteLine("Error writing data.")
Return
End If
Next i
Console.WriteLine("The data was written to {0} and verified.", fileStream.Name)
Finally
fileStream.Close()
End Try
End Sub
End Class