File.CreateText(String fileName) : File « System.IO « C# / C Sharp by API






File.CreateText(String fileName)

  

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();
    }
  }
}

   
    
  








Related examples in the same category

1.File.Delete
2.File.Exists(String fileName)
3.File.GetLastAccessTime
4.File.OpenRead
5.File.OpenText
6.File.OpenWrite
7.File.ReadAllLines(String fileName)
8.File.SetAccessControl
9.File.WriteAllLines(String fileName, String[] lines)