In the C#,Textreader and TextWriter are the another way to read and write file respectively which is class is found under System.IO namespace.
C# TextReader Example: Read All Data
using System; using System.IO; namespace TextReaderExample
{ public class Program { public static void Main(string[] args) { using (TextReader tr = File.OpenText("d:\\test.txt")) { Console.WriteLine(tr.ReadToEnd()); } } } }
Output
Hello FindAndSolve
C# File Handling by FindAndSolve
C# TextReader Example: Read One Line
TextReader class that reads single line from the file.
using System;
using System.IO;
namespace TextReaderExample
{ public class Program
{
static void Main(string[] args)
{
using (TextReader tr = File.OpenText("d:\\test.txt"))
{
Console.WriteLine(tr.ReadLine());
}
}
}
}
Output
Hello FindAndSolve