怎么txt中文乱码是乱码?求指点
File.WriteAllText("C:\\file.txt", ""); //创建一个文件流,用以写入或者创建一个StreamWriter
FileStream fs = new FileStream("C:\\file.txt", FileMode.OpenOrCreate, FileAccess.Write);
StreamWriter m_streamWriter = new StreamWriter(fs);
m_streamWriter.Flush();
// 使用StreamWriter来往文件中写入内容
m_streamWriter.BaseStream.Seek(0, SeekOrigin.Begin);
// 把richTextBox1中的内容写入文件
m_streamWriter.Write("姓名:" + T_KQ_xs.Rows[0]["name"].ToString().Trim() + "\r\n");
m_streamWriter.Write("工号:" + T_KQ_xs.Rows[0]["bianma"].ToString().Trim() + "\r\n");
m_streamWriter.Write("所属班组:" + T_KQ_xs.Rows[0]["banzu_name"].ToString().Trim() + "\r\n");
//关闭此文件
m_streamWriter.Flush();
m_streamWriter.Close();
fs.Close()
------------------------------
我这样读出来的txt是中文乱码,怎么解决乱码问题啊?
------解决方案--------------------StreamWriter m_streamWriter = new StreamWriter(fs,Encoding.GetEncoding("gb2312"));
------解决方案-------------------- FileStream fs = new FileStream("C:\\file.txt", FileMode.OpenOrCreate, FileAccess.Write);
StreamWriter m_streamWriter = new StreamWriter(fs,Encoding.GetEncoding("gb2312"));
加上编码
------解决方案-------------------- StreamWriter m_streamWriter = new StreamWriter(fs,Encoding.GetEncoding("gb2312"));
编码。。
------解决方案--------------------第一眼看下去就知道是
StreamWriter m_streamWriter = new StreamWriter(fs,Encoding.GetEncoding("gb2312"));
------解决方案--------------------StreamWriter 加上编码格式 楼上的都是正解!!!!