string text = File.ReadAllText(@"c:file.txt", Encoding.UTF8);
string[] lines = File.ReadAllLines(@"c:file.txt", Encoding.UTF8);
string contents = File.ReadAllText(@"C: emp est.txt");
using System;
using System.IO;
public class Example
{
public static void Main()
{
string fileName = @"C:examplepath.txt";
using (StreamReader streamReader = File.OpenText(fileName))
{
string text = streamReader.ReadToEnd();
string[] lines = text.Split(Environment.NewLine);
foreach (string line in lines) {
Console.WriteLine(line);
}
}
}
}
using(StreamReader file = new StreamReader(textFile)) {
int counter = 0;
string ln;
while ((ln = file.ReadLine()) != null) {
Console.WriteLine(ln);
counter++;
}
file.Close();
}
/// 08/04/2022 Mahesh Kumar Yadav. <br/>
/// <summary>
/// Read file and split line one by one
/// </summary>
internal static void ReadFileAndSplitByLine(string filePath)
{
using (var streamReader = File.OpenText(filePath))
{
var text = streamReader.ReadToEnd();
var lines = text.Split(new[] { Environment.NewLine }, StringSplitOptions.None);
foreach (var line in lines)
{
Console.WriteLine(line);
}
}
}