Ad

Saturday, July 27, 2013

Reading a Text File Using One Line At a Time?

Overview:
             In this article i would like to publish an article "Reading a Text File Using One Line At a Time".



Description:
                   It can be possible by using the concept of files and stream.
we can store an information in another text file we specify the location path.

For using this we  can use the Following namespace
               
                                     Using System.IO;
For reading of an data we use the class i.e...,
                                                   StreamReader
 For writing of an data we use the class i.e...,
                                                   StreamWriter
 Process of Execution:
 In this i would like to save ".txt" file named as "get.txt" in the "D" drive.

Program:


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

namespace dt
{
    class Class3
    {
        static void Main(string[] args)
        {
            int counter = 0;
            string line;

            // Read the file and display it line by line.
            System.IO.StreamReader file =
               new System.IO.StreamReader("d:\\get.txt");
            while ((line = file.ReadLine()) != null)
            {
                Console.WriteLine(line);
                counter++;
            }

            file.Close();

            // Suspend the screen.
            Console.ReadLine();
        }
    }
}

OutPut: 

No comments: