static void TestComtradeConfig() { while (true) { try { Console.WriteLine("TestComtrade-TestStart"); string str; using (var file = File.OpenRead(@"file\cfg.cfg")) { StreamReader stream = new StreamReader(file); str = stream.ReadToEnd(); } Console.WriteLine(); Console.WriteLine(); Console.WriteLine(str); Console.WriteLine(); Console.WriteLine(); ComtradeConfigFile comtrade = new ComtradeConfigFile(); comtrade.FileToRowMessage(str); string path = @"file\" + DateTime.Now.Minute.ToString() + "_" + DateTime.Now.Second.ToString() + ".cfg"; using (var file = File.OpenWrite(path)) { StreamWriter stream = new StreamWriter(file); string[] strcollect; comtrade.MakeConfigFile(out strcollect); foreach (var m in strcollect) { stream.Write(m); } stream.Flush(); } Console.WriteLine("TestComtrade-TestEnd"); var instr = Console.ReadLine(); if (instr == "q") { return; } } catch (Exception ex) { Console.WriteLine(ex.Message); var instr = Console.ReadLine(); if (instr == "q") { return; } } } }
/// <summary> /// 读取配置文件 /// </summary> /// <param name="path">配置文件路径</param> public void ReadConfigFile(string path) { try { string configFile; using (var file = File.OpenRead(path)) { StreamReader stream = new StreamReader(file); configFile = stream.ReadToEnd(); } ConfigFile.FileToRowMessage(configFile); } catch (Exception ex) { throw ex; } }