在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
读取文件内容有三种方式
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 = new System.IO.StreamReader(@"c:\test.txt"); while((line = file.ReadLine()) != null) { System.Console.WriteLine(line); counter++; } file.Close(); System.Console.WriteLine("There were {0} lines.", counter);
全部读取到字符串数组中,每个数组元素存储一行文本string[] lines = System.IO.File.ReadAllLines(@"C:\Users\Public\TestFolder\WriteLines2.txt");
|
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论