Working with textfiles in vb.net

Posted in: Files and Folders
By dePoPo
Mar 6, 2009 - 11:47:59 AM

Some examples for working with text files in vb.net



' Write data to a text file
' imports system.io

           
 Dim outfile As New StreamWriter("file.txt")
 outfile.WriteLine("line 1")
 outfile.WriteLine("line 2")
 outfile.Close()
 
 
' read data from a text file
 Dim s_linebuffer As String
 Dim infile As New StreamReader("file.txt")
 Do While infile.EndOfStream = False
 s_linebuffer = infile.ReadLine
 Loop
 infile.Close()
 
 
'check if a file exists, and delete it if it does
 If File.Exists("somepoorfile.txt") Then
 File.Delete("somepoorfile.txt")
 End If


Visitor Comments