c#读取文件写文件
/// summary /// 读文件方法 /// /summary /// param name="filename"文件名/param /// returns文件内容/returns private string ReadFile(string filename) { string str = ""; string filenamepath = filename; //打开文件 StreamReader sr = File.OpenTex
///
/// 读文件方法
///
/// 文件名
///
private string ReadFile(string filename)
{
string str = "";
string filenamepath = filename;
//打开文件
StreamReader sr = File.OpenText(filenamepath);
str = sr.ReadToEnd();
sr.Close();
return str;
}
///
/// 写文件方法
///
/// 文件名
/// 文件内容
public void WriteFile(string Path, string Strings)
{
StreamWriter sw = null;
try
{
sw = new StreamWriter(Path, false, System.Text.Encoding.UTF8);
sw.Write(Strings);
sw.Flush();
}
catch (Exception exp)
{
HttpContext.Current.Response.Write(exp.Message);
HttpContext.Current.Response.End();
}
finally
{
sw.Close();
}
}