c#读取.txt文件,中文乱码问题
我正在做读取文件的一个小东西,但从文本文件中读出的中文都是乱码,我用的是下列程序,请问该怎么解决
using (StreamReader sr = new StreamReader (file))
{
string text="";
String line;
char[] tempChars;
while ((line = sr.ReadLine()) != null)
{
byte[] msg=Encoding.Unicode.GetBytes(line);
Decoder uniDecoder = Encoding.Unicode.GetDecoder();
int charCount = uniDecoder.GetCharCount(msg, 0, msg.Length);
tempChars = new Char[charCount];
int charsDecodedCount = uniDecoder.GetChars(msg, 0, msg.Length, tempChars, 0);
foreach (Char c in tempChars)
{
Console.Write("[{0}]", c);
}
string temp=new string(tempChars);
System.Diagnostics.Debug.WriteLine(temp);
text+=temp;
}
arrayList.Add(text);
}