.NET 创建并写CSV文件

  /// <summary>
/// 创建并写日志
/// </summary>
/// <param name="SuccessA100"></param>
/// <param name="Result"></param>
public void WriteLog(List<string> SuccessA100,string Result,string A102)
{
if (SuccessA100 == null)
{
return;
}
string txtPath = AppDomain.CurrentDomain.BaseDirectory + "log\\" +A102 + "\\"+ Result +A102.Replace("-", "")+DateTime.Now.ToString("yyyyyMMdd") + ".csv"; if (!File.Exists(txtPath))
{
if (!Directory.Exists(AppDomain.CurrentDomain.BaseDirectory + "log\\" + A102 ))
{
Directory.CreateDirectory(AppDomain.CurrentDomain.BaseDirectory + "log\\" + A102);
} FileStream fs1 = new FileStream(txtPath, FileMode.Create, FileAccess.Write);//创建写入文件
using (StreamWriter sw = new StreamWriter(fs1))
{
sw.WriteLine("A001,");
foreach (string a100 in SuccessA100)
{
sw.WriteLine(a100+",");//开始写入值
}
sw.Close();
fs1.Close();
}
}
else
{
FileStream fs = new FileStream(txtPath, FileMode.Append, FileAccess.Write);
using (StreamWriter sw = new StreamWriter(fs))
{
foreach (string a100 in SuccessA100)
{
sw.WriteLine(a100 + ",");//开始写入值
}
sw.Close();
fs.Close();
} }
Thread.Sleep();
}
上一篇:【BZOJ】1303: [CQOI2009]中位数图(特殊的技巧)


下一篇:使用Intent创建Tab页面