C#的中文编码问题,求解诶
这是数据写入TXT的
private void button1_Click(object sender, EventArgs e)
{
if (!File.Exists(path))
{
FileStream fs1 = new FileStream(path, FileMode.Create, FileAccess.Write); //创建文件
StreamWriter sw = new StreamWriter(fs1,System.Text.Encoding.Default);
sw.WriteLine(textBox1.Text.Trim() + "\t" + textBox2.Text.Trim()); //写入值
sw.Close();
fs1.Close();
}
else
{
StreamWriter sr = File.AppendText(path);
sr.WriteLine(textBox1.Text.Trim() + "\t" + textBox2.Text.Trim()); //写入值
sr.Close();
}
readini(path);
}
这是读出的
public void readini(string url)
{
DataTable dt = new DataTable();
dt.Columns.Add("名称", typeof(String));
dt.Columns.Add("指令", typeof(String));
using (StreamReader reader = new StreamReader(url,System.Text .Encoding.Default))
{
while (!reader.EndOfStream)
{
string[] data = reader.ReadLine().Replace("\t", "\t").Split('\t');
DataRow dr = dt.NewRow();
dr[0] = data[0];
dr[1] = data[1];
&nbs