Reading From a Text File in C#

前端 未结 8 1646
轮回少年
轮回少年 2020-11-30 09:44

I have the following program that will send (output) information to a text file, but now I want to read (input) from the text file. Any suggestions would be greatly appreci

8条回答
  •  渐次进展
    2020-11-30 10:24

    Try this:

    if(result == DialogResult.OK && fileName != null)
    {
        try
        {
            var fileText=File.ReadAllText(fileName);
        }
        catch(Exception ex)
        {
            //Handle exception here
        }
    }
    

    It will read all the data from the selected file into the fileText variable.

提交回复
热议问题