Reading ASCII file from the end?!
-
I have to read the last 5 lines of several very very huge ASCII files, several times. I want to see if it is possible to read only those last lines, instead of reading the whole junk data and getting to those 5 ending lines. Could someone please help me, how to decrease this amount of waste of cpu time and un-wanted I/O?
-
I have to read the last 5 lines of several very very huge ASCII files, several times. I want to see if it is possible to read only those last lines, instead of reading the whole junk data and getting to those 5 ending lines. Could someone please help me, how to decrease this amount of waste of cpu time and un-wanted I/O?
You could set the position in the stream, but im not sure how accurate that would be. The position is the current index in the huge array of bytes that is your text file, so if you knew the length of the text file... For example, you have a text file with 5000 characters in it, you set the position too 4500, and then read the last 500 characters. That way you don't need to waste time reading the first 4500 characters. The only problem is, how do you know where to start reading from? I'll leave that to you ;) to set the position, i think its just:
myStream.Position = somewhere;
I think it's .Position anyway, it might be .Location, i'm sure you'll find it.My current favourite word is: PIE! Good ol' pie, it's been a while.
-
You could set the position in the stream, but im not sure how accurate that would be. The position is the current index in the huge array of bytes that is your text file, so if you knew the length of the text file... For example, you have a text file with 5000 characters in it, you set the position too 4500, and then read the last 500 characters. That way you don't need to waste time reading the first 4500 characters. The only problem is, how do you know where to start reading from? I'll leave that to you ;) to set the position, i think its just:
myStream.Position = somewhere;
I think it's .Position anyway, it might be .Location, i'm sure you'll find it.My current favourite word is: PIE! Good ol' pie, it's been a while.
Yes, and there is also .Length A) Set the Position to Length B) Read backward until you encounter the fifth newline C) Reverse the string
-
Yes, and there is also .Length A) Set the Position to Length B) Read backward until you encounter the fifth newline C) Reverse the string
Thank you! This looks so fine!