文件读取问题
在文件读取的时候这样获取到要读取的文件里的数据的行数啊?请指教!
谢谢……
using System; using System.Collections.Generic; using System.Text; using ConsoleApplication1 { class Program { static void Main(string[] args) { FileStream fs = new FileStream("xxx.txt", FileMode.Open); StreamReader sr = new StreamReader(fs); int rows = 0; string line = sr.ReadLine(); while (line != null) { rows++; line = sr.ReadLine(); } Console.WriteLine(rows.ToString()); Console.Read(); } } }