zoukankan      html  css  js  c++  java
  • .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(1000);
            }
  • 相关阅读:
    第11组 Alpha冲刺(4/6)
    第11组 Alpha冲刺(3/6)
    第11组 Alpha冲刺(2/6)
    第11组 Alpha冲刺(1/6)
    团队Git现场编程实战
    第11组 团队项目-需求分析报告
    团队项目-选题报告
    第10组 Alpha冲刺(2/6)
    第10组 Alpha冲刺(1/6)
    2019 SDN上机第2次作业
  • 原文地址:https://www.cnblogs.com/liuruitao/p/5302788.html
Copyright © 2011-2022 走看看