C#读取html文件
string strLine; using (System.IO.StreamReader sr = new System.IO.StreamReader(C:\text.html)) { strLine = sr.ReadLine(); } System.Console.WriteLine(strLine);
和读txt基本类似
我之前发的读行数的html也适用
public static int readFileLines(string path) //这里的参数是txt所在路径 { int lines = 0; //用来统计txt行数 FileStream fs = new FileStream(path, FileMode.OpenOrCreate, FileAccess.ReadWrite); StreamReader sr = new StreamReader(fs); while (sr.ReadLine() != null) { lines++; } fs.Close(); sr.Close(); return lines; }