www.mzixi.com:谁能给我段快速精简的 文件遍历源代码(C#)

来源:百度文库 编辑:高考问答 时间:2024/04/30 00:24:32

遍历目录下所有文件的:
foreach(string fileName in System.IO.Directory.GetFiles("<dir-path>", "*.*"))
{
..............
}

遍历文件所有行的:
FileStream fs = new FileStream("<dir-path>", FileMode.Open, FileAccess.Read);
StreamReader streamReader = new StreamReader(fs, System.Text.Encoding.Default);
string data = streamReader.ReadLine();

while (data != null && data.Length > 0)
{
..............
description = streamReader.ReadLine();
}
fs.Close();