C# Program to Write Text to a File

You are currently viewing C# Program to Write Text to a File

C# program to write text to a file

using System;

//We need to include this namespace for file handling.
using System.IO;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main()
        {
            string s;

            Console.WriteLine("Enter text to Write into File : ");
            s = Console.ReadLine();

            File.WriteAllText("ABC.TXT",s);
            Console.WriteLine("\nFile Creation Done");
        }
    }
}

Output

Enter text to Write into File :
Hello , This is a sample program for writing text into file.

File Creation Done

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