使用 System.IO.File 类从文件读取

你可以使用 System.IO.File.ReadAllText 函数将文件的全部内容读入字符串。

string text = System.IO.File.ReadAllText(@"C:\MyFolder\MyTextFile.txt");

你还可以使用 System.IO.File.ReadAllLines 函数将文件读取为行数组 :

string[] lines = System.IO.File.ReadAllLines(@"C:\MyFolder\MyTextFile.txt");