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.

A simple CSharp Text Reader source code



Textreader and TextWriter are another way to read and write a file, respectively, even though these do not stream classes. The StreamReader and StreamWriter classes are derived from TextReader and TextWriter classes, respectively. The following program uses TextReader, Read the entire content of the file into a String.

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");
                line = readFile.ReadToEnd();
                MessageBox.Show(line);
                readFile.Close();
                readFile = null;
            }
            catch (IOException ex)
            {
                MessageBox.Show(ex.ToString());
            }
        }
    }
}

When you execute this C# program, TextReader read the entire file in one stretch into a string.


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