Is it? Until you open the file as a stream, the data to do so is kicking around your code as a string type with compiler checks on usage. You're making my point: a compile time check is much more helpful.
From your example it looked to me like the types in question were "file" types. You're right that "file name" types are not checked by these languages.