读取文件内容有三种方式
- 全部读取到字符串变量中
- 一次读取一行
- 全部读取到字符串数组中,每个数组元素存储一行文本
全部读取到字符串变量
string text = System.IO.File.ReadAllText(@"C:\Users\Public\TestFolder\WriteText.txt"); System.Console.WriteLine("Contents of WriteText.txt = {0}", text);
一次读取一行
int counter = 0; string line; System.IO.StreamReader file =