File.Exists() Method in C# with Examples Last Updated : 28 Apr, 2025 Comments Improve Suggest changes Like Article Like Report File.Exists(String) is an inbuilt File class method that is used to determine whether the specified file exists or not. This method returns true if the caller has the required permissions and path contains the name of an existing file; otherwise, false. Also, if the path is null, then this method returns false. Syntax: public static bool Exists (string path); Here, path is the specified path that is to be checked. Program 1: Before running the below code, a file file.txt is created with some contents shown below: CSharp // C# program to illustrate the usage // of File.Exists(String) method // Using System and System.IO namespaces using System; using System.IO; class GFG { static void Main() { // Checking the existence of the specified if (File.Exists("file.txt")) { Console.WriteLine("Specified file exists."); } else { Console.WriteLine("Specified file does not "+ "exist in the current directory."); } } } Output: Specified file exists. Program 2: Before running the below code, no file is created. CSharp // C# program to illustrate the usage // of File.Exists(String) method // Using System and System.IO namespaces using System; using System.IO; class GFG { static void Main() { // Checking the existence of the specified if (File.Exists("file.txt")) { Console.WriteLine("Specified file exists."); } else { Console.WriteLine("Specified file does not"+ " exist in the current directory."); } } } Output: Specified file does not exist in the current directory. Comment More infoAdvertise with us Next Article File.Exists() Method in C# with Examples K Kanchan_Ray Follow Improve Article Tags : C# CSharp-File-Handling Similar Reads File.Move() Method in C# with Examples File.Move() is an inbuilt File class method that is used to move a specified file to a new location. This method also provides the option to specify a new file name. Syntax: public static void Move (string sourceFileName, string destFileName); Parameter: This function accepts two parameters which ar 2 min read File.Delete() Method in C# with Examples File.Delete(String) is an inbuilt File class method which is used to delete the specified file.Syntax:Â Â public static void Delete (string path); Parameter: This function accepts a parameter which is illustrated below:Â Â path: This is the specified file path which is to be deleted. Exceptions:Â Argu 3 min read File.OpenRead() Method in C# with Examples File.OpenRead(String) is an inbuilt File class method which is used to open an existing file for reading.Syntax:Â Â public static System.IO.FileStream OpenRead (string path); Parameter: This function accepts a parameter which is illustrated below:Â Â path: This is the specified file which is going to 2 min read File.OpenText() Method in C# with Examples File.OpenText(String) is an inbuilt File class method which is used to open an existing UTF-8 encoded text file for reading.Syntax:Â Â public static System.IO.StreamReader OpenText (string path); Parameter: This function accepts a parameter which is illustrated below:Â Â path: This is the specified te 2 min read File.OpenWrite() Method in C# with Examples File.OpenWrite(String) is an inbuilt File class method that is used to open an existing file or creates a new file for writing. Syntax:Â public static System.IO.FileStream OpenWrite (string path); Parameter: This function accepts a parameter which is illustrated below:Â path: This is the specified t 3 min read File.CreateText() Method in C# with Examples File.CreateText() is an inbuilt File class method that is used to overwrite the contents of the existing file with the given UTF-8 encoded text and if the file is not created already, this function will create a new file with the specified contents. Syntax:Â public static System.IO.StreamWriter Crea 3 min read File.AppendText() Method in C# with Examples File.AppendText() is an inbuilt File class method which is used to create a StreamWriter that appends UTF-8 encoded text to an existing file else it creates a new file if the specified file does not exist.Syntax:Â Â public static System.IO.StreamWriter AppendText (string path); Parameter: This functi 3 min read File.ReadAllBytes() Method in C# with Examples File.ReadAllBytes(String) is an inbuilt File class method that is used to open a specified or created binary file and then reads the contents of the file into a byte array and then closes the file.Syntax:Â Â public static byte[] ReadAllBytes (string path); Parameter: This function accepts a parameter 2 min read File.GetCreationTime() Method in C# with Examples File.GetCreationTime(String) is an inbuilt File class method which is used to return the creation date and time of the specified file or directory. Syntax: public static DateTime GetCreationTime (string path); Parameter: This function accepts a parameter which is illustrated below: path: This is the 2 min read File.Create(String) Method in C# with Examples File.Create(String) is an inbuilt File class method which is used to overwrites an existing file else create a new file if the specified file is not existing. Syntax:Â public static System.IO.FileStream Create (string path); Parameter: This function accepts a parameter which is illustrated below: 3 min read Like