jonahxuworld
2022-02-28 15:54
采纳率: 95.7%
浏览 80

C#winform如何读取目录下所有TXT文件,并且计算每个文件的行数呢?

RT,我就只会写到这里,不知道如何操作,求指教!


        private void button1_Click(object sender, EventArgs e)
        {
            FolderBrowserDialog dialog = new FolderBrowserDialog();
            dialog.Description = "请选择文件路径";

            if (dialog.ShowDialog() == DialogResult.OK)
            {
                string savePath = dialog.SelectedPath.ToString();
                textBox1.Text = savePath;

                string str;

                StreamReader sr = new StreamReader(@"C:\python测试\2.txt", false);
                str = sr.ReadLine().ToString();
                sr.Close();
                textBox2.Text = str;

            }
        }

3条回答 默认 最新

相关推荐 更多相似问题