Dim binReader As New BinaryReader( _
File.Open(fileName, FileMode.Open))
Try
' If the file is not empty,
' read the application settings.
' First read 4 bytes into a buffer to
' determine if the file is empty.
Dim testArray As Byte() = {0,0,0,0}
Dim count As Integer = binReader.Read(testArray, 0, 3)
If count <> 0 Then
' Reset the position in the stream to zero.
binReader.BaseStream.Seek(0, SeekOrigin.Begin)
aspRatio = binReader.ReadSingle()
lkupDir = binReader.ReadString()
saveTime = binReader.ReadInt32()
statusBar = binReader.ReadBoolean()
Return
End If
' If the end of the stream is reached before reading
' the four data values, ignore the error and use the
' default settings for the remaining values.
Catch ex As EndOfStreamException
Console.WriteLine("{0} caught and ignored. " & _
"Using default values.", ex.GetType().Name)
Finally
binReader.Close()
End Try