Why do i get 'filenotfoundexception in c#'?

Example:

StreamReader sr = new StreamReader("nonexistent.txt");
Solution:

This exception is raised when trying to access a file that doesn't exist. Ensure the file path is correct and the file exists at the specified location.


if(File.Exists("path.txt")) {
    StreamReader sr = new StreamReader("path.txt");
}

Beginner's Guide to C#