I have a text file and I want to read this text file from a particular till end of file.
I can do this by the following way.
string path = @"C:\abc.txt";
var pp = File.ReadAllLines(path).Skip(1).Take(2);
But I want this to be done using StreamReader only.
I'm doing this, but its not giving proper result.
using (Stream stream = File.Open(path, FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
{
using (StreamReader streamReader = new StreamReader(stream))
{
var str = streamReader.ReadLine().Skip(1).Take(2);
}
}
I can do this by the following way too. but I want to avoid the for loop.
using (Stream stream = File.Open(path, FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
{
using (StreamReader streamReader = new StreamReader(stream))
{
int count=2;
for (int i = 0; i < count; i++)
{
streamReader.ReadLine();
}
string data = streamReader.ReadLine();
}
}
My question is not duplicate at all, previous one is about reading all files but my question is read from specific line till end.