Create text file using File.CreateText : File Create : File Directory Stream C# Examples


C# Examples » File Directory Stream » File Create »

 

Create text file using File.CreateText









    
using  System;
using  System.IO;

class  MainClass
{
    static  void  Main(string[]  args)
    {
        StreamWriter  MyStream  =  null;
        string  MyString  =  "Hello  World";

        try
        {
            MyStream  =  File.CreateText("MyFile.txt");
            MyStream.Write(MyString);
        }
        catch  (IOException  e)
        {
            Console.WriteLine(e);
        }
        catch  (Exception  e)
        {
            Console.WriteLine(e);
        }
        finally
        {
            if  (MyStream  !=  null)
                MyStream.Close();
        }
    }
}
    
   
  
   




HTML code for linking to this page:

Follow Navioo On Twitter

C# Examples

 Navioo File Directory Stream
» File Create