using System;
using System.IO;

namespace FIleStreamReaderSimple
{
    class Program
    {
        private const string FILE_NAME = "MyFile.txt";
        static void Main(string[] args)
        {
            if (!File.Exists(FILE_NAME))
            {
                Console.WriteLine("{0} does not exist!", FILE_NAME);
                return;
            }
            FileStream fsIn = new FileStream(FILE_NAME, FileMode.Open,
                                            FileAccess.Read, FileShare.Read);
            // Create an instance of StreamReader that can read
            // characters from the FileStream.
            using (StreamReader sr = new StreamReader(fsIn))
            {
                // While not at the end of the file, read lines from the file.
                while (sr.Peek() > -1)
                {
                    string input = sr.ReadLine();
                    Console.WriteLine(input);
                }
            }
            Console.ReadKey();

            FileStream fsIn2 = new FileStream(FILE_NAME, FileMode.Open,
                                            FileAccess.Read, FileShare.Read);
            using (StreamReader sr = new StreamReader(fsIn2))
            {
                // While not at the end of the file, read lines from the file.
                while (!sr.EndOfStream)
                {
                    string input = sr.ReadLine();
                    Console.WriteLine(input);
                }
            }
            Console.ReadKey();
        }
    }
}
