Hi all,
Ive been trying to find a seek method for StreamReader. I want to be able to reverse the file buffer by a couple characters at a time.
How I have everything set up.
private void SortThread()
{
string[] lines;
string line,
totalLine = null;
char[] fileInput = new char[1001];
TextReader tr;
tr = new StreamReader("C:\\Users\\Anon\\Desktop\\test.txt");
line = null;
do
{
try
{
//read 1k characters at a time
tr.Read(fileInput, 0, 1000);
//turn them to an array of lines
line = new string(fileInput);
lines = line.Split('\n');
//go backwards in the buffer and remove last line
int reverse = lines[lines.Count() - 1].Length;
lines[lines.Count() - 1] = null;
//buffer goes back by the amount in reverse
}
catch (Exception e)
{
MessageBox.Show(e.ToString());
}
} while (line != null);
tr.Close();
}
The reason for this is because its reading 1000 characters at a time (for managing the lines array later; faster) it will have the last line incomplete. So I remove the last line and reverse back by the incomplete size. So when it reads again it will start at the beginning of the last line that was incomplete. Also is it going to throw an exception when I try to read 1000 char and theres less than 1k in the file?