#region 向文本文件写入内容
/// <summary>
/// 向文本文件中写入内容
/// </summary>
/// <param name="filePath">文件的绝对路径</param>
/// <param name="text">写入的内容</param>
public static void WriteText(string text, string filePath)
{
bool isAppend = true;
FileInfo fi = new FileInfo(filePath);
DirectoryInfo di = fi.Directory;
if (!di.Exists)
{
di.Create();
}
System.IO.StreamWriter sw = new System.IO.StreamWriter(filePath, isAppend, Encoding.UTF8);
try
{
sw.Write(text); sw.Flush();
}
finally
{
if (sw != null) { sw.Close(); sw.Dispose(); }
}
}
#endregion
/// <summary>
/// 向文本文件中写入内容
/// </summary>
/// <param name="filePath">文件的绝对路径</param>
/// <param name="text">写入的内容</param>
public static void WriteText(string text, string filePath)
{
bool isAppend = true;
FileInfo fi = new FileInfo(filePath);
DirectoryInfo di = fi.Directory;
if (!di.Exists)
{
di.Create();
}
System.IO.StreamWriter sw = new System.IO.StreamWriter(filePath, isAppend, Encoding.UTF8);
try
{
sw.Write(text); sw.Flush();
}
finally
{
if (sw != null) { sw.Close(); sw.Dispose(); }
}
}
#endregion