读取文本文件出现问题
我设计一个读取文本文件的小程序,可是只要是遇到汉字就会显示成小方块。怎么回事啊?
StreamReader streamReader;
streamReader = File.OpenText(openFileDialog1.FileName);
textBox1.Text = streamReader.ReadToEnd();
------解决方案--------------------//普通的文本文件是GB2312编码,参考如下代码
using (StreamReader streamReader = new StreamReader(
@ "c:\temp\temp.txt ", Encoding.Default))
textBox1.Text = streamReader.ReadToEnd();
写入用
using (StreamWriter vStreamWriter = new StreamWriter(
@ "c:\temp\temp.txt ", false, Encoding.GetEncoding( "GB2312 ")))
vStreamWriter.Write( "Zswang 路过 ");