Writing data into CSV file in C#

后端 未结 15 1359
清酒与你
清酒与你 2020-11-22 17:15

I am trying to write into a csv file row by row using C# language. Here is my function

string first = reader[0].ToString();
string second=image.         


        
15条回答
  •  鱼传尺愫
    2020-11-22 17:30

    One simple way to get rid of the overwriting issue is to use File.AppendText to append line at the end of the file as

    void Main()
    {
        using (System.IO.StreamWriter sw = System.IO.File.AppendText("file.txt"))
        {          
            string first = reader[0].ToString();
            string second=image.ToString();
            string csv = string.Format("{0},{1}\n", first, second);
            sw.WriteLine(csv);
        }
    } 
    

提交回复
热议问题