日期:2014-05-16 浏览次数:20444 次
/// <summary>
private static StreamReader sr;
private static StreamWriter sw;
/// 读取文件
/// </summary>
/// <param name="Path">文件路径</param>
/// <param name="Coding">文件编码</param>
/// <returns></returns>
public static string Reader(string Path, string Coding)
{
string str = "";
if (File.Exists(Path))
{
try
{
sr = new StreamReader(Path, Encoding.GetEncoding(Coding));
str = sr.ReadToEnd();
sr.Close();
}
catch (Exception e)
{
throw new Exception(e.Message, e);
}
}
return str;
}
/// <summary>
/// 写入文件
/// </summary>
/// <param name="Path">文件路径</param>
/// <param name="Text">写入内容</param>
/// <param name="Coding">文件编码</param>
public static void Writer(string Path, string Text, string Coding)
{
if (File.Exists(Path))
{
Delete(Path);
}
try
{
sw = new StreamWriter(Path, false, Encoding.GetEncoding(Coding));
sw.WriteLine(Text);
sw.Flush();
&nbs