文件IO操作! #region 文件IO操作! /**//// <summary> /// 创建/写入文件内容 /// </summary> /// <param name="FileName">文件名(默认当前目录/包含路径)</param> /// <param name="FileContent">文件内容</param> /// <param name="act">改写(false)/追加到文件尾部(true)</param> /// <returns>返回bool</returns> public static bool IO_CreatTextFile(string FileName, string FileContent, bool act) ...{ try ...{ StreamWriter writer1 = new StreamWriter(FileName, act, Encoding.Default); writer1.Write(FileContent); writer1.Close(); } catch ...{ return false; } return true; } /**//// <summary> /// 得到文件内容 /// </summary> /// <param name="TextFilePath">文件路径</param> /// <returns>文件内容字符串</returns> public static string IO_GetFileContent(string TextFilePath) ...{ FileStream stream1 = new FileStream(TextFilePath, FileMode.Open, FileAccess.Read); byte[] buffer1 = new byte[(int)stream1.Length]; stream1.Read(buffer1, 0, buffer1.Length); stream1.Close(); return Encoding.Default.GetString(buffer1); } /**//// <summary> /// 读取文件内容 /// </summary> /// <param name="TextFilePath">文件路径</param> /// <returns></returns> public static string IO_GetFileContent1(string TextFilePath) ...{ FileStream fs = new FileStream(TextFilePath, FileMode.Open); StreamReader sr = new StreamReader(fs); string s = ""; while (sr.BaseStream.Position < sr.BaseStream.Length) ...{ s += sr.ReadLine(); } return s; } #endregion