文件写入写出的封装
#region 文件写入写出的封装
/// <summary>
/// 写入文件方法
/// </summary>
/// <param name="filePath">要被写入的文件的路径</param>
/// <param name="fileConten">要被写入内容</param>
/// <returns></returns>
public bool StreamWrite(string filePath,string fileConten,HttpServerUtility Server)
{
try
{
string content = fileConten.ToString();
string path = Server.MapPath(filePath);
StreamWriter strwriterobj = new StreamWriter(path, false, System.Text.Encoding.GetEncoding("GB2312"));
strwriterobj.WriteLine(content);
strwriterobj.Close();
return true;
}
catch
{
return false;
}
}
/// <summary>
/// 读取文件方法
/// </summary>
/// <param name="filePath">要被读取的文件的路径</param>
/// <param name="boxCon">接收内容的文本框</param>
/// <returns></returns>
public bool StreamRead(string filePath,TextBox boxCon,HttpServerUtility Server)
{
try
{
string path = Server.MapPath(filePath);
StreamReader sr = new StreamReader(path, System.Text.Encoding.GetEncoding("GB2312"), true);
boxCon.Text = sr.ReadLine().ToString();
return true;
}
catch
{
return false;
}
}
#endregion