Getsuyodev, Programming is mainly used when constructing an application. Programming requires knowledge of application domains, algorithms, and programming language expertise. Programming can be developed in different logic based on developer knowledge.

How to use CSharp Textreader Class



Textreader and TextWriter are another way to read and write a file, respectively, even though these do not stream classes. Textreader represents a reader that can read a sequential series of characters. The StreamReader and StreamWriter classes are derived from TextReader and TextWriter classes respectively, which read characters from streams and strings.

The following C# source code shows how to read a file using TextReader.

using System;
using System.Windows.Forms;
using System.IO;
using System.Text;

namespace WindowsApplication1
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            try
            {
                string line = null;
                System.IO.TextReader readFile = new StreamReader("C:\\getsuyodev.txt");
                while (true)
                {
                    line = readFile.ReadLine();
                    if (line != null)
                    {
                        MessageBox.Show (line);
                    }
                }
                readFile.Close();
                readFile = null;
            }
            catch (IOException ex)
            {
                MessageBox.Show(ex.ToString());
            }
        }
    }
}

Comments are closed.

This website uses cookies to improve your experience. We'll assume you're ok with this, but you can opt-out if you wish. Accept Read More