Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

C# StreamWriter help

  1. Jun 3, 2009 #1
    Can someone please, using the following data, show me how to write this data to a CSV file using the StreamWriter class in C#.

    Bob,1,2,3
    Jim,4,5,6
    Tom,7,8,9
     
  2. jcsd
  3. Jul 2, 2009 #2

    harborsparrow

    User Avatar
    Gold Member

    using System.IO; // file readers and writers

    string myInputLine = "some line to be written to a file";

    string fileSpecification = "C:\test1.txt";

    StreamWriter filewriter = new StreamWriter(
    fileSpecification, true, System.Text.Encoding.UTF8);

    filewriter.WriteLine(myInputLine);
    filewriter.Flush();

    filewriter.Close();
     
Share this great discussion with others via Reddit, Google+, Twitter, or Facebook