Click here to Skip to main content
15,892,005 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
How to read the text content from text file and write it back to the console window using while loop ????
Posted

Use the StreamReader[^] class to read the data and the Console[^] class to display it.

If you are new to C# then I recommend working through .NET Book Zero[^] by Charles Petzold, and the C# Tutorials[^] on MSDN.
 
Share this answer
 
or use
string Data = File.ReadAllText(@"Path");


and then split it like

string[] Multi = Data.Split('\n');


then by looping

for(int i=0;i<multi.length;i++)>
{
    Console.WriteLine(Multi[i].ToString());
}
 
Share this answer
 
Hi
Try this code..


C#
static void Main(string[] args)
       {

           string path = "D://file.txt";
           string[] lines = System.IO.File.ReadAllLines(path);
           int i = 0;
           while (i < lines.Length)
           {
               Console.WriteLine(lines[i]);
               i++;
           }

           Console.Read();
       }
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900