Program char_by_char.cs
Demonstrates use of StreamReader object's Read() method
using System;
using System.IO;
class Program {
static void Main() {
StreamReader sr;
string from_file = string.Empty;
int fileChar = 0;
sr = File.OpenText("myfile.txt");
while((fileChar = sr.Read()) != -1){
from_file += Convert.ToChar(fileChar);
}
if (from_file == "") {
Console.WriteLine("No data was read from the text file. Apparently the file is empty\n");
} else {
Console.WriteLine("The file contents are:\n");
Console.WriteLine("\"" + from_file + "\"\n\n");
}
Console.Write("Press the Enter key to end the program... ");
Console.ReadLine();
}//end method Main()
}//end class Program