StreamReader is unable to correctly read extended character set (UTF8)

Viewed 7349

I am having an issue where I am unable to read a file that contains foreign characters. The file, I have been told, is encoded in UTF-8 format.

Here is the core of my code:

using (FileStream fileStream = fileInfo.OpenRead())
{
    using (StreamReader reader = new StreamReader(fileStream, System.Text.Encoding.UTF8))
    {
        string line;

        while (!string.IsNullOrEmpty(line = reader.ReadLine()))
        {
            hashSet.Add(line);
        }
    }
}

The file contains the word "achôcre" but when examining it during debugging it is adding it as "ach�cre".

(This is a profanity file so I apologize if you speak French. I for one, have no idea what that means)

1 Answers
Related