关于记事本程序执行打开这一步骤的问题
为什么我写的那个代码在测试的时候,打开后,文件里边的内容要么是显示出来是缺少几行,或者是显示不出中文什么的,显示乱码。
回复 楼主 shiyongjian
对了,我写的代码:private void OpenToolStripMenuItem_Click(object sender, EventArgs e)
{
OpenFileDialog Open = new OpenFileDialog();
Open.Filter = "(*.txt)|*.txt|(*.*)|*.*";
Open.FilterIndex = 1;
if (Open.ShowDialog() != DialogResult.OK)
return;
try
{
StreamReader sw = new StreamReader(Open.FileName, true);
string a = sw.ReadLine();
while (sw.ReadLine() != null)
{
richTextBox1.Text +=a;
richTextBox1.Text += "\r\n";
a = sw.ReadLine();
}
sw.Close();
}
catch(IOException ex)
{
MessageBox.Show(ex.Message);
return;
}
}