C# 文件读取方法,自己写的例子,保存一下,备用
生活随笔
收集整理的這篇文章主要介紹了
C# 文件读取方法,自己写的例子,保存一下,备用
小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
/// <summary>/// 將output.config內(nèi)容傳到app.config/// </summary>string ReadString;//兩個(gè)地址string path1 = @"D:\wcf\xml文件讀寫\Xml_WirteOrRead\Xml_WirteOrRead\output.config";string path2 = @"D:\wcf\xml文件讀寫\Xml_WirteOrRead\Xml_WirteOrRead\app.config"; /// <summary>/// 讀文件/// </summary>/// <param name="path"></param>public void ReadFile(string path){try{FileStream afile = new FileStream(path, FileMode.Open);StreamReader sread = new StreamReader(afile);//ReadString = sread.ReadLine();ReadString = sread.ReadToEnd(); sread.Close();afile.Close();}catch (Exception ex){MessageBox.Show(ex.Message);}}/// <summary>/// 寫文件/// </summary>public void WriteFile(){try {FileStream afile = new FileStream(path2, FileMode.OpenOrCreate);StreamWriter swrite = new StreamWriter(afile);if (!string.IsNullOrEmpty(ReadString)){ swrite.Write(ReadString);// swrite.WriteLine(ReadString);
} swrite.Close();afile.Close(); }catch (Exception ex){MessageBox.Show(ex.Message);}}
C# 對(duì)于文件的讀取與寫入!!個(gè)人做的一個(gè)小例子!
轉(zhuǎn)載于:https://www.cnblogs.com/chcong/p/4303353.html
總結(jié)
以上是生活随笔為你收集整理的C# 文件读取方法,自己写的例子,保存一下,备用的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: Why React?
- 下一篇: ecshop常用二次开发修改