用c#读取文件内容中文是乱码的解决方法:
//方法1:
- StreamReader din = new StreamReader(@"C:1.txt", System.Text.Encoding.GetEncoding("gb2312"));
- string html = "";
- while (din.Peek() > -1)
- {
- html = html + din.ReadToEnd();
- }
- din.Close();
//方法2:
- StreamReader sr1 = new StreamReader((System.IO.Stream)File.OpenRead(filename), System.Text.Encoding.Default);
- html = "";
- while (sr1.Peek() > -1)
- {
- html = html + sr1.ReadLine();
- }
- sr1.Close();
//方法3:
- StreamReader objReader = new StreamReader(@"C:1.txt", System.Text.Encoding.GetEncoding("gb2312"));
- string sLine = "", html = "";
- while (sLine != null)
- {
- sLine = objReader.ReadLine();
- if (sLine != null)
- html += sLine;
- }
- objReader.Close();