Use while loop to read a text file : Text File Read Write : File Directory Stream C# Examples


C# Examples » File Directory Stream » Text File Read Write »

 

Use while loop to read a text file









    
using  System;
using  System.IO;

class  MainClass
{
    public  static  void  Main(string[]  args)
    {
        try
        {
            StreamReader  sr  =  File.OpenText("c:\\boot.ini");
            string  strLine;
            while(null  !=  (strLine  =  sr.ReadLine()))
            {
                Console.WriteLine(strLine);
            }
            sr.Close();
        }
        catch(FileNotFoundException  e)
        {
            Console.WriteLine(e.Message);
        }
    }
}
    
   
  
   



Output

[boot loader]
timeout=30
default=multi(0)disk(0)rdisk(0)partition(1)\WINDOWS
[operating systems]
multi(0)disk(0)rdisk(0)partition(1)\WINDOWS="Microsoft Windows XP Home Edition" /noexecute=optin /fa
stdetect


HTML code for linking to this page:

Follow Navioo On Twitter

C# Examples

 Navioo File Directory Stream
» Text File Read Write