create a new text file and write a line to it - CSharp File IO

CSharp examples for File IO:Text File

Description

create a new text file and write a line to it

Demo Code

using static System.Console;
using static System.IO.Directory;
using static System.IO.Path;
using static System.Environment;
using System.IO;/*from  w w w . jav  a2 s . c  om*/
class Program
{
   static void Main(string[] args)
   {
      StreamWriter textWriter = File.CreateText("z.txt");
      textWriter.WriteLine("Hello, C#!");
      textWriter.Close(); // close file and release resources
   }
}

Related Tutorials