Tag Archives: Writeline

Write Text to a Text File with Stream Writer Class using VB.NET

Click Star to Rate Post
1 Star2 Stars3 Stars4 Stars5 Stars (3 votes, average: 4.33 out of 5)
 

This will use the Stream Writer class under the System.IO namespace to write text to a textfile.

        '
        'Write to text file with the Stream Writer Class
        Dim sWriter As IO.StreamWriter = New IO.StreamWriter("c:\newTextFile.txt")

        'This is pretty much easy to understand. No explanation 
        sWriter.WriteLine("Hi")

        sWriter.WriteLine("Testing out this code")

        sWriter.WriteLine("Hopefully this code will work")

        sWriter.WriteLine("Lets flush the stream and see")

        'Flush all data to the file.   
        sWriter.Flush()

        sWriter.Close()