WPF读写文件

一、利用StreamReader 与 StreamWriter读写文件 

1.读文件

1 StreamReader sr = new StreamReader(@"D:\JointIn.txt");
2 string sLine = "";
3 while(!sr.EndOfStream)
4 {
5        sLine += sr.ReadLine();
6 }
7 Console.WriteLine(sLine); 
8 sr.Close(); 

2.写文件

1 StreamWriter sw = new StreamWriter(@"D:\JointOut.txt",true);//追加
2 sw.WriteLine("Hello World");
3 sw.Flush();
4 sw.Close();

二、读取XML节点

string XExamVideoConfigPath = @"D:\Test\VideoConfig.xml";
XmlDocument doc = new XmlDocument();
doc.Load(XExamVideoConfigPath);
string nodePath = "/Configuration/Node/Value[@index=1]";
var videoUrlNode = doc.SelectSingleNode(nodePath);
videoUrlNode.InnerText = "rtsp://admin:a12345678@172.24.14.64:554";
doc.Save(XExamVideoConfigPath);

 

posted @ 2022-09-09 15:17  LXLR  阅读(658)  评论(0编辑  收藏  举报