Reading an writing test files in csharp

From MyWiki
Revision as of 21:48, 27 March 2015 by George2 (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

Writing to a Text File
Listing 1: Writing Text Data to a File: TextFileWriter.cs

using System;
using System.IO;
 
namespace csharp_station.howto
{
    class TextFileWriter
    {
        static void Main(string[] args)
        {
            // create a writer and open the file
            TextWriter tw = new StreamWriter("date.txt");
 
            // write a line of text to the file
            tw.WriteLine(DateTime.Now);
 
            // close the stream
            tw.Close();
        }
    }
}