WORKAROUND
To work around this problem, you must specify the correct UTF encoding by using the
StreamReader class, or you must save the text file by using UTF encoding.
The following example shows how to read a text file by using UTF encoding. This example uses the encoding
System.Text.Encoding.Default property that corresponds to the system's current ANSI code page.
Visual Basic .NET or Visual Basic 2005
Imports System
Imports System.IO
Module module1
Sub Main()
Dim sr As StreamReader = New StreamReader("c:\tmp\TestFile.txt", _
System.Text.Encoding.Default)
Dim line As String
' Read and display the lines from the file until the end
' of the file is reached.
Do
line = sr.ReadLine()
Console.WriteLine(line)
Loop Until line Is Nothing
sr.Close()
End Sub
End Module
C#
using System;
using System.IO;
class Class1
{
static void Main(string[] args)
{
StreamReader sr = new StreamReader("c:\\tmp\\TestFile.txt",
System.Text.Encoding.Default);
string line;
// Read and display the lines from the file until the end
// of the file is reached.
while ((line = sr.ReadLine()) != null)
Console.WriteLine(line);
sr.Close();
}
}
Note In Visual Studio 2005, by default, Program.cs is created.
Note When you pass the
System.Text.Encoding.Default property as the second parameter of the
StreamReader method, the system's current ANSI code page is used to decode the file.