30 January 2014

How to Read Text from a File in c#.net

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;

namespace How_to_Read_Text_from_a_File
{
    class Program
    {
        public static void Main()
        {
            try
            {
                using (StreamReader sr = new StreamReader("adi.txt"))
                {
                    String line = sr.ReadToEnd();
                    Console.WriteLine(line);
                }
            }
            catch (Exception e)
            {
                Console.WriteLine("The file could not be read:");
                Console.WriteLine(e.Message);
                
            }
            Console.ReadLine();
        }
    }
}
 
 

No comments:

Post a Comment