实现效果:
知识运用:
StreamReader类的构造 和ReadToEnd方法
public StreamReader (string path, Encoding encoding )
实现代码:
private void button1_Click(object sender, EventArgs e) { try { openFileDialog1.Filter = "文本文件(*.txt)|*.txt"; openFileDialog1.ShowDialog(); StreamReader sr = new StreamReader(textBox1.Text,Encoding.Default); textBox2.Text = sr.ReadToEnd(); sr.Close(); } catch (Exception) { MessageBox.Show("请选择文件!"); } }