C#文件保存读取怎么出现乱码
小弟才开始学C# 有些问题麻烦各位大师帮忙
我的代码是
using System;
using System.IO;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
namespace text
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void CheckSave()
{
if (richTextBox1.Text != "")
{
if (MessageBox.Show("是否保存当前文件?", "确认", MessageBoxButtons.OKCancel) == DialogResult.OK)
{
MySaveFile();
}
}
}
private void MyNewFile()
{
CheckSave();
richTextBox1.Clear();
statusStrip1.Text = "新建文件";
}
private void MySaveFile()
{
statusStrip1.Text = "保存文件";
saveFileDialog1.Filter = "文本文件(*.txt)|*.txt";
if (saveFileDialog1.ShowDialog() == DialogResult.OK)
{
richTextBox1.SaveFile(saveFileDialog1.FileName);
}
}
private void MyOpenFile()
{
CheckSave();
openFileDialog1.Filter ="文本文件(*.txt)|*.txt";
if (openFileDialog1.ShowDialog() == DialogResult.OK)
{
using (StreamReader read = new StreamReader(openFileDialog1.FileName, Encoding.Default))
{
richTextBox1.Text = read.ReadToEnd();
}
}
}
private void 打开ToolStripMenuItem_Click(object sender, EventArgs e)
{
MyOpenFile();
}
private void 新建ToolStripMenuItem_Click(object sender, EventArgs e)
{
MyNewFile();
}
private void 保存ToolStripMenuItem_Click(object sender, EventArgs e)
{
MySaveFile();
}
}
}
我先写一个文件 但是保存后再打开就出现很多乱码 这是什么原因
谢谢!!!!!