Class FileRead
Public Sub Open(ByVal fileToRead As FileStream)
' This If statement is optional
' as it is very unlikely that
' the stream would ever be null
If IsDBNull(fileToRead) Then
Throw New System.ArgumentNullException()
End If
Dim b As Integer
' Set the stream position to the beginning of the file.
fileToRead.Seek(0, SeekOrigin.Begin)
' Read each byte to the end of the file.
For i As Integer = 0 To fileToRead.Length
b = fileToRead.ReadByte()
Console.Write(b.ToString())
' Or do something else with the byte.
Next
End Sub
End Class
class FileRead {
public void Open(FileStream fileToRead)
{
// This if statement is optional
// as it is very unlikely that
// the stream would ever be null.
if (fileToRead == null)
{
throw new System.ArgumentNullException();
}
int b;
// Set the stream position to the beginning of the file.
fileToRead.Seek(0, SeekOrigin.Begin);
// Read each byte to the end of the file.
for (int i = 0; i < fileToRead.Length; i++)
{
b = fileToRead.ReadByte();
Console.Write(b.ToString());
// Or do something else with the byte.
}
}
}