How to capture file not found exception in C#?
Answers
Answered by
0
Answer:
The file not found exception is raised when you try to find a file that does not exist.
Let’s say I have set a file in StreamReader, “new.txt” that does not exist. If you will try to access it using StreamReader(to read it), it will throw FileNotFoundException −
using (StreamReader sReader = new StreamReader("new.txt")) {
sReader.ReadToEnd();
}
To handle it, you need to use try and catch −
Try {
using (StreamReader sReader = new StreamReader("new.txt")) {
sReader.ReadToEnd();
}
}catch (FileNotFoundException e) {
Console.WriteLine("File Not Found!");
Console.WriteLine(e);
}
Explanation:
Answered by
0
Explanation:
✪✪ssksiewwsokksoisosoww
Similar questions
History,
6 months ago
Computer Science,
6 months ago
Computer Science,
1 year ago
History,
1 year ago
History,
1 year ago
English,
1 year ago