VB.net Program to Read the Content of a File Character by Character

You are currently viewing VB.net Program to Read the Content of a File Character by Character

VB.Net program to read the content of a file character by character

'Vb.Net program to read data from file 
'character by character till the end of the file.

Imports System.IO
Imports System.Text

Module Module1
    Sub Main()
        Dim stream As New FileStream("C:\data.txt", FileMode.Open)
        Dim val As Integer
        Dim ch As Char
        Dim flag As Boolean = True
        Console.WriteLine("Content of file: ")
        While (flag = True)
            val = stream.ReadByte()

            If (val < 0) Then
                flag = False
            Else
                ch = Convert.ToChar(val)
                Console.Write(ch)
            End If
        End While
    End Sub
End Module
Content of file:
It is a book.
It is a table.
It is a fan.
Press any key to continue . . .

Ranjith Kumar

Hi, I'm Ranjith a full-time Blogger, YouTuber, Affiliate Marketer, & founder of Coding Diksha. Here, I post about programming to help developers.

Leave a Reply