110,535
社区成员
发帖
与我相关
我的任务
分享
try
{
// string errorDirectory = @"D:\Program Files\error_salary"; //如果该目录不存在将创建
string errorPath = @"D:\Program Files\error_salary" + "\\" + fileName +".txt";
//start access file
if (!System.IO.File.Exists(errorPath))
{
// Create a file to write to.
using (System.IO.StreamWriter sw = System.IO.File.CreateText(errorPath))
{
sw.WriteLine( exceptionString ); //将导常写入文件.
}
}
else
{
// This text is always added, making the file longer over time
// if it is not deleted.
using (System.IO.StreamWriter sw2 = System.IO.File.AppendText(errorPath))
{
sw2.WriteLine();
// sw.WriteLine(sqlTable);
sw2.WriteLine(DateTime.Now + " ");
sw2.WriteLine( exceptionString );
}
}
//end
}
catch (Exception ec)
{
Console.WriteLine(ec.ToString());
}