static void Main(string[] args)
{
//读取为一个字符串
string text = System.IO.File.ReadAllText(@"E:\visual studio 2015 test\IOTest2.TXT");
//读取为字符串数组,每行一个字符串
string[] lines = System.IO.File.ReadAllLines(@"E:\visual studio 2015 test\IOTest1.TXT");
//StreamReader类,以流的方式读取
System.IO.StreamReader sr = new System.IO.StreamReader(@"E:\visual studio 2015 test\IOTest3.TXT");
string str;
while ((str = sr.ReadLine()) != null)
{
Console.WriteLine(str);
}
sr.Close();
Console.ReadKey();
}
C#练习---4(读取文本文件)
最新推荐文章于 2024-05-04 21:03:09 发布