 
 Data Structure Data Structure
 Networking Networking
 RDBMS RDBMS
 Operating System Operating System
 Java Java
 MS Excel MS Excel
 iOS iOS
 HTML HTML
 CSS CSS
 Android Android
 Python Python
 C Programming C Programming
 C++ C++
 C# C#
 MongoDB MongoDB
 MySQL MySQL
 Javascript Javascript
 PHP PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
FileNotFoundException in C#
If a File you are trying to find does not exist, then FileNotFoundException occurs.
Here, we are try to find a file that does not exist using StreamReader() method.
reader = new StreamReader("new.txt"))
To read it we have used the following method −
reader.ReadToEnd();
Let us see the complete code.
Example
using System.IO;
using System;
class Program {
   static void Main() {
      using (StreamReader reader = new StreamReader("new.txt")) {
         reader.ReadToEnd();
      }
   }
}
The above code will generate the following exception since the file “new.txt” does not exist.
Unhandled Exception: System.IO.FileNotFoundException: Could not find file …
Advertisements
                    