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(); } } }
reading from a text file
listing 2 shows how to read from a text file: listing 2: reading text data from a file: textfilereader.cs
using system; using system.io;
namespace csharp_station.howto { class textfilereader { static void main(string[] args) { // create reader & open file textreader tr = new streamreader( "date.txt ");
// read a line of text console.writeline(tr.readline());