visual studio 2010 写入汉字出现乱码怎么解决?
发表在C#图书答疑
2014-12-02
是否精华
是
否
版块置顶:
是
否
namespace WindowsFormsApplication20
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
if (File.Exists(textBox1.Text))
{
StreamReader sr = new StreamReader(textBox1.Text,Encoding .Default );
textBox2.Text = sr.ReadToEnd();
sr.Close();
}
else
textBox2.Text = "文件不存在";
}
private void button2_Click(object sender, EventArgs e)
{
if (File.Exists(textBox1.Text))
{
StreamWriter sw = new StreamWriter(textBox1.Text);
sw.Write( textBox2.Text );
sw.Close();
}
else
textBox2.Text = "文件不存在";
}
读出文件后在vs的textBox2中显示的乱码,麻烦问下该怎么解决啊?
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
if (File.Exists(textBox1.Text))
{
StreamReader sr = new StreamReader(textBox1.Text,Encoding .Default );
textBox2.Text = sr.ReadToEnd();
sr.Close();
}
else
textBox2.Text = "文件不存在";
}
private void button2_Click(object sender, EventArgs e)
{
if (File.Exists(textBox1.Text))
{
StreamWriter sw = new StreamWriter(textBox1.Text);
sw.Write( textBox2.Text );
sw.Close();
}
else
textBox2.Text = "文件不存在";
}
读出文件后在vs的textBox2中显示的乱码,麻烦问下该怎么解决啊?