日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

文件处理封装

發(fā)布時間:2023/12/10 编程问答 27 豆豆
生活随笔 收集整理的這篇文章主要介紹了 文件处理封装 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
/// <summary>/// 文件處理封裝/// </summary> public static class FileHelper{/// <summary>/// 讀取Txt文件/// </summary>/// <param name="FilePath">文件地址</param>/// <returns>文件內(nèi)容</returns>public static string ReadTxtFile(string FilePath){if (!File.Exists(FilePath)) throw new Exception("指定的文件不存在或已刪除!");return File.ReadAllText(FilePath);}/// <summary>/// 往Txt文件寫入內(nèi)容/// </summary>/// <param name="FilePath"> 文件地址</param>/// <param name="Contents">內(nèi)容</param>/// <param name="IsCover"> 是否覆蓋原內(nèi)容</param>public static void WriteTxtFile(string FilePath, string Contents, bool IsCover){if (!IsCover && File.Exists(FilePath)){using (StreamReader sr = new StreamReader(FilePath)){Contents = sr.ReadToEnd() + " \r\n" + Contents;sr.Close();}}using (StreamWriter sw = new StreamWriter(FilePath)){sw.Write(Contents);sw.Close();}}/// <summary>/// 往Txt文件寫入內(nèi)容/// </summary>/// <param name="FilePath">文件地址</param>/// <param name="Contents">內(nèi)容</param>/// <param name="IsCover">是否覆蓋原內(nèi)容</param>public static void WriteTxtFile(string FilePath, string[] Contents, bool IsCover){string OldContents = string.Empty;if (!IsCover && File.Exists(FilePath)){using (StreamReader sr = new StreamReader(FilePath)){OldContents = sr.ReadToEnd();sr.Close();}}using (StreamWriter sw = new StreamWriter(FilePath)){sw.WriteLine(OldContents);foreach (String str in Contents)sw.WriteLine(str);sw.Close();}}}

?

轉(zhuǎn)載于:https://www.cnblogs.com/AllUserBegin/p/4424177.html

總結(jié)

以上是生活随笔為你收集整理的文件处理封装的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。