smritz
smritz

Reputation: 118

F# - Weird FileNotFound Exception

I basically just have this:

open System.Net
open System.IO 

let reader = new StreamReader("students.txt")
let csv = reader.ReadToEnd()

For some reason this throws a File Not Found Exception. It tells me it could not find the file at "C:\Users\Shane\ownCloud\Home\Assign18\Assign18\bin\Debug\students.txt" even though that is exactly where the file is. This happens even if I put the full file path to students.txt, or if I move it to another location.

Anyone have any idea what is going on?

Upvotes: 0

Views: 162

Answers (2)

smritz
smritz

Reputation: 118

Turns out I'm just not very used to using Windows (only running it for Visual Studio). So when I named the file "Students.txt", I didn't realize that Windows already had a file extension for that file that it was hiding from me. So the whole time, the file was actually called "Students.txt.txt"

Upvotes: 2

David
David

Reputation: 10708

Make sure to run the program as an administrator - new StreamReader(string) does not mention a specific exception when file permissions are violated, and thus may be wrapping it.

Note that File.Open and the aformentioned File.ReadAllText methods mention specific exceptions when encountering access violations, and thus may throw more descriptive (helpful) exceptions.

Upvotes: 1

Related Questions