I'm trying to do something basic, read a UTF-8 encoded text file and display it to the console. Everytime I run the script my output is the following:
The file i'm trying to read is here: https://www.gutenberg.org/cache/epub/49724/pg49724.txt
I have no idea why I'm getting this output. I'm sure its something incredibly stupid that I'm overlooking but I've dumbed my code down to the following to try and identify the problem.
static void Main(string[] args)
{
DateTime end;
DateTime start = DateTime.Now;
Console.WriteLine("### Overall Start Time: " + start.ToLongTimeString());
Console.WriteLine();
ReadFile();
end = DateTime.Now;
Console.WriteLine();
Console.WriteLine("### Overall End Time: " + end.ToLongTimeString());
Console.WriteLine("### Overall Run Time: " + (end - start));
Console.WriteLine();
Console.WriteLine("Hit Enter to Exit");
Console.ReadLine();
}
static void ReadFile() {
string fileName = "snow-white.txt";
try
{
foreach (string line in File.ReadLines(fileName, Encoding.UTF8))
{
Console.WriteLine("-- {0}", line);
}
}
catch (Exception Ex)
{
Console.WriteLine(Ex.ToString());
}
}
Any help would be greatly appreciated.
Thanks,