0

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?

smritz
  • 108
  • 6

2 Answers2

2

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"

smritz
  • 108
  • 6
  • 4
    To avoid this in the future: Control panel -> Folder Options -> "View" tab -> untick "Hide extensions for known file types" :) – Tarmil Nov 14 '14 at 10:38
  • FYI for "strongly typed" access to file paths, there is a [FileSystem type provider](http://fsprojects.github.io/FSharp.Management/FileSystemProvider.html) (part of the FSharp.Management NuGet). – Marc Sigrist Nov 14 '14 at 17:31
1

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.

David
  • 10,458
  • 1
  • 28
  • 40