Example

using System;
using System.IO;
namespace Samples
{
  public class FileSample
  {
    public static void Main()
    {
      string s = @"File.txt";
      if(File.Exists(s))
      {
        Console.WriteLine("File {0} already exists", s);
        File.Delete(s);
      }
      using(StreamWriter sw = File.CreateText(s))
      {
        Console.WriteLine("Can read: {0}",
                          sw.BaseStream.CanRead);
        Console.WriteLine("Can write: {0}",
                          sw.BaseStream.CanWrite);
        sw.WriteLine(DateTime.Now);
      }
    }
  }
}
The output is
File File.txt already exists
Can read: False
Can write: True

Get .NET Framework Standard Library Annotated Reference, Volume 1: Base Class Library and Extended Numerics Library now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.