在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
废话不多说,直接上源码(控制台应用程序写的) public static void ReadTXTFile() { try { FileInfo handlingFile = null; //指定文档路径 DirectoryInfo sourceFolder = new DirectoryInfo(@"D:\netnetnetnetnetnetnet\ConsoleApplication1\ConsoleApplication1\bin\Debug"); FileInfo[] txtFiles = sourceFolder.GetFiles("*.txt") ;//指定文档格式 for (int idxFile = 0; txtFiles != null && idxFile < txtFiles.Length; ++idxFile)//遍历每个txt文件 { List<string> lstAddStr = new List<string>(); handlingFile = txtFiles[idxFile]; StreamReader srTxt = new StreamReader(handlingFile.OpenRead(), System.Text.Encoding.Default); string strReadLine = srTxt.ReadLine(); for (; strReadLine != null; strReadLine = srTxt.ReadLine()) { if (strReadLine.Trim() == string.Empty)//去掉空白行 { continue; } lstAddStr.Add(strReadLine);//读取文档每一行 add 到lstAddStr } Dictionary<string, string> dictPara = new Dictionary<string, string>(); for (int i = 0; i < lstAddStr.Count; i++)//遍历每个行 { Console.WriteLine(lstAddStr[i]); //if (lstAddStr[i].StartsWith("1")) //对数据进行判断处理 //{ // //} } } } catch (Exception ex) { Console.WriteLine(ex.ToString()); } }
运行结果:
|
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论