Csharp.Net-informations.com   Advertisement
     SiteMap

How to use C# Textreader Class

C# Textreader and TextWriter are the another way to read and write file respectively, even though these are not stream classes. The StreamReader and StreamWriter classes are derived from TextReader and TextWriter classes respectively. The following C# sample source code showing how create and write in a file using C# TextWriter .

Next :  How to use C# BinaryWriter Class



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
            {
                System.IO.TextWriter writeFile = new StreamWriter("c:\\textwriter.txt");
                writeFile.WriteLine("csharp.net-informations.com");
                writeFile.Flush();
                writeFile.Close();
                writeFile = null;
            }
            catch (IOException ex)
            {
                MessageBox.Show(ex.ToString());
            }
        }
    }
}

When you execute this C# source code , you will get a file TextWriter.txt and inside its written csharp.net-informations.com .

CSharp File (I/O) Operations - Related Contents


CSharp File (I/O) Operations - Related Programs


More Source Code :
|  Home  |   VB.NET  |   C#  |   ASP.NET  |   SiteMap  |   Terms of Use  |   About  |