读取文件

1. 读取目录下的文件

  string path=@"d:pinlog";

  Files[] files= Directory.GetFiles(path,"*.txt");

 Foreach(File file in files)

{

   StreamReader reader=new StreamReader(file);

    string headText=reader.ReadLine();//读取第一行

    string bodyText=reader.ReadToEnd();

}

2. 获取更多的信息

DirectoryInfo folder=new DirectoryInfo(path);

Foreach(FileInfo fileInfo in folder.GetFiles(".txt"))

{

  string fileName=fileInfo.FullName;

}

原文地址:https://www.cnblogs.com/dennysong/p/5360599.html