Quantcast
Channel: Learn C#
Viewing all articles
Browse latest Browse all 10

How to read data from a text file in c#?

$
0
0

string filePath = @”c:\Sample.txt”;

string line,SNo=” “;

if (File.Exists(filePath))

{

StreamReader file = null;

try

{

file = new StreamReader(filePath);

while ((line = file.ReadLine()) != null)

{

Console.WriteLine(line);

//SNo = line.Substring(0,3);

}

}

finally

{

if (file != null)

file.Close();

}

}

Udhaya



Viewing all articles
Browse latest Browse all 10

Trending Articles