C# 读文件操作
代码
List<string> rows = new List<string>();
string all = string.Empty;
using (StreamReader sr = new StreamReader(@"D:\myText.txt", Encoding.UTF8))
{
//读取每一行
while (sr.Peek() >= 0)
{
rows.Add(sr.ReadLine());
}
//所有内容
all = sr.ReadToEnd();
}
代码
List<string> rows = new List<string>();
string all = string.Empty;
using (StreamReader sr = new StreamReader(@"D:\myText.txt", Encoding.UTF8))
{
//读取每一行
while (sr.Peek() >= 0)
{
rows.Add(sr.ReadLine());
}
//所有内容
all = sr.ReadToEnd();
}