Imports System.IO
Module Module1
Sub Main()
Try
Dim sr As StreamReader = File.OpenText("c:\\data.txt")
Console.WriteLine("The first text: {0}", sr.ReadLine())
sr.Close()
Catch e As Exception
Console.WriteLine(e)
End Try
End Sub
End Module
' run:
'
' System.IO.FileNotFoundException: Could not find file 'c:\data.txt'.
' File name: 'c:\data.txt'
' at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)
' at System.IO.FileStream.Init(String path, FileMode mode, FileAccess access, I
' nt32 rights, Boolean useRights, FileShare share, Int32 bufferSize, FileOptions o
' ptions, SECURITY_ATTRIBUTES secAttrs, String msgPath, Boolean bFromProxy, Boolea
' n useLongPath, Boolean checkHost)
' at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access,
' FileShare share, Int32 bufferSize, FileOptions options, String msgPath, Boolean
' bFromProxy, Boolean useLongPath, Boolean checkHost)
' at System.IO.StreamReader..ctor(String path, Encoding encoding, Boolean detec
' tEncodingFromByteOrderMarks, Int32 bufferSize, Boolean checkHost)
' at System.IO.StreamReader..ctor(String path)
' at System.IO.File.OpenText(String path)
' at ConsoleApplication_Visual_Basic.Module1.Main() In D:\directx\ConsoleApplic
' ation_Visual_Basic\ ConsoleApplication_Visual_Basic \ Module1.vb: line 9