实现效果:

  读取文件中的第一行数据

知识运用:

  StreamReader类的ReadLine方法    //从当前流中读取一行字符并将数据作为字符串返回

  public override string ReadLine ()

实现代码:

        private void button1_Click(object sender, EventArgs e)
        {
            try
            {
                OpenFileDialog open = new OpenFileDialog();
                open.Filter = "文本文件(*.txt)|*.txt";
                open.ShowDialog();
                textBox1.Text = open.FileName;
                StreamReader sr = new StreamReader(textBox1.Text, Encoding.UTF8);
                label3.Text = sr.ReadLine();
                sr.Close();
            }
            catch (Exception ex)
            { MessageBox.Show(ex.Message); }
        }

  

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2021-07-15
  • 2022-12-23
  • 2022-12-23
  • 2021-12-20
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2021-09-16
  • 2022-12-23
  • 2022-12-23
  • 2021-11-22
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案