Code Newbie
News     Forums     Search     Members     Sign Up    

My Code Newbie
Username

Password

Articles/Snippets
ASP Classic
ASP.NET
C
C#
C++
HTML / CSS
Java
Javascript
Linux / BSD
Perl
PHP
Python
Ruby
SQL
VB 6
VB.NET

C.N. Friends
  Planet Rome

Link to Us!
Code Newbie
  Code Newbie
    csharp
  » Read and Write to a Text File
      by sde
 Page 1 of 1 
   

(Login to remove green text ads)
This is a very simple way to read and write to a text file using TextReader and TextWriter.

First you need to include System.IO
Code:
using System.IO;
Reading a Text File:
Code:
static void Main(string[] args) { // create reader & open file TextReader tr = new StreamReader("date.txt"); // read a line of text Console.WriteLine(tr.ReadLine()); // close the stream tr.Close(); }
Writting a Text File
Code:
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(); }





 
 Page 1 of 1 
   

Rate This Article
1 2 3 4 5 6 7 8 9 10





Copyright © 2000-2006, Milano Interactive
Web Hosting provided by Portal 360 Web Hosting
Open Circle