Friday, March 18, 2005

 

StreamReader

StreamReader is StreamWriter’s counterapart.

Here’s a short program to read a text file:

using System;
using System.IO;

class LearnStreamReadWrite
{
public static void Main()
{
string fileName = @"..\..\Class1.cs";

StreamReader fileRead = new StreamReader(fileName);

// Read the content of the file
string aLine = null;
while( (aLine = fileRead.ReadLine()) != null )
{
Console.WriteLine(aLine);
}

}

}

Comments: Post a Comment

<< Home

This page is powered by Blogger. Isn't yours?