日期:2014-05-17 浏览次数:20934 次
//点击打开按钮的事件
private void miOpen_Click(object sender, EventArgs e)
{
OpenFileDialog dig=new OpenFileDialog();
dig.ShowDialog();
if (dig.FileName!="")
{
SetTitle(dig.FileName);
filename = dig.FileName;
OpenFile(dig.FileName);//调用OpenFile方法
}
else
{
MessageBox.Show("请选择文件!");
}
}
//打开文件的方法
protected void OpenFile(string path)
{
try
{
textBox1.Clear();
textBox1.Text = File.ReadAllText(path, UnicodeEncoding.GetEncoding("GB2312")); //文件的读取
}
catch(IOException e)
{
MessageBox.Show(e.Message, "hhh",MessageBoxButtons.OK,MessageBoxIcon.Exclamation);
}
}
string path = @"E:\CollegeStudy\c# 资料\C__WCF入门学习.txt";
StreamReader sr = new StreamReader(path, Encoding.GetEncoding("GB2312"));
string text = sr.ReadToEnd();
Console.WriteLine(text);
sr.Close();