C# program to read data from file character by character till the end of the file

Sometimes we get frustrated if we do not get the information we need in some articles. But this article has all the information you need when you read C# program to read data from file character by character till the end of the file. Read patiently and understand.

C# program to read data from file character by character till the end of the file

C# program to read data from file character by character till the end of the file

//C# program to read data from file 
//character by character till the end of the file.

using System;
using System.IO;
using System.Text;

class Demo
{
    static void Main()
    {
        Stream s = new FileStream(@"d:\data.txt", FileMode.Open);
        int val = 0;
        char ch;

        while (true)
        {
            val = s.ReadByte();

            if (val < 0)
                break;
            ch = (char)val;
            Console.Write(ch);
        }
        Console.WriteLine();
    }
}
This is a bag.
This is a bat.
This is a ball.
Press any key to continue . . .

Final Words

We hope the C# program to read data from file character by character till the end of the file article helped you in some way. And let us know if you have any doubts. Thanks

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

Share on:

Leave a Comment