C#之IO讀寫文件辦法封裝代碼。本站提示廣大學習愛好者:(C#之IO讀寫文件辦法封裝代碼)文章只能為提供參考,不一定能成為您想要的結果。以下是C#之IO讀寫文件辦法封裝代碼正文
詳細不做具體引見了,直接上代碼
/// <summary> /// 功效:FileStream文件流讀取文件 /// </summary> /// <param name="filePath">參數:文件途徑</param> /// <returns>前往值:StreamReader對象</returns> public static StreamReader ReadFileByFs(string filePath) { FileStream Fs = null; StreamReader Sr = null; try { Fs = new FileStream(filePath, FileMode.OpenOrCreate, FileAccess.Read); Sr = new StreamReader(Fs, Encoding.Default); } catch (IOException e) { throw e; } return Sr; }
代碼 2:
/// <summary> /// 功效:FileStream文件流寫文件 /// </summary> /// <param name="filePath">參數:文件途徑</param> /// <returns>前往值:StreamWriter對象</returns> public static StreamWriter WriteFileByFs(string filePath) { FileStream Fs = null; StreamWriter Sw = null; try { Fs = new FileStream(filePath, FileMode.OpenOrCreate, FileAccess.Write); Sw = new StreamWriter(Fs, Encoding.Default); } catch (IOException e) { throw e; } return Sw; }
以上代碼針對IO讀寫文件辦法封裝做了具體引見,願望可以或許贊助到年夜家。