#region 操作文本文件 /// <summary> /// 读取文件 /// </summary> /// <param name="strPath">文件路径</param> /// <param name="strValue">文件内容</param> /// <returns></returns> public void readFile(string strPath, string strValue) { FileStream fsInfo = new FileStream(strPath, FileMode.Open, FileAccess.Read); StreamReader srInfo = new StreamReader(fsInfo, System.Text.Encoding.GetEncoding("GB2312")); srInfo.BaseStream.Seek(0, SeekOrigin.Begin); strValue = " "; string strLine = srInfo.ReadToEnd(); while (strLine != null) { strValue += strLine + "\n"; strLine = srInfo.ReadLine(); } srInfo.Close(); } /// <summary> /// 写入文件 /// </summary> /// <param name="strPath">文件路径</param> /// <param name="strValue">文件内容</param> /// <returns></returns> public void writeFile(string strPath, string strValue) { FileStream fsInfo = new FileStream(strPath, FileMode.OpenOrCreate, FileAccess.Write); StreamWriter swInfo = new StreamWriter(fsInfo); swInfo.Flush(); swInfo.BaseStream.Seek(0, SeekOrigin.Begin); swInfo.Write(strValue); swInfo.Flush(); swInfo.Close(); } #endregion