I have a very huge text file with size "662 MB" and its can't be opened by a notepad on my computer so I created a program to only read the last line because there is a software that is writing to this file some counts, so I don't want the counts to be repeated so if the computer happens to shutdown or crash, I use this program to read only the last line of this file and populate the text on the last line.
Now the problem is that I don't know what happened but a battery was drained and the laptop shutdown and someone tried to turn it on but that coursed the computer to dump everything because the battery was already low. Now the problem is that the program the time the computer was started while the battery was drained the program only wrote a blank on a text file so the last line is blank.
How can I read the secondlast, thirdlast line on a text file?
Here is the code I use to read only the last line.
Using sr As New StreamReader(File.OpenRead("D:\test")) Dim LastLine As String, I, J As Integer, P As Long Do I = 0 : J += 128 : P = sr.BaseStream.Length - J If P < 0 Then P = 0 sr.BaseStream.Position = P Do LastLine = sr.ReadLine : I +=1 Loop Until sr.EndOfStream Loop Until I > 1 Or P = o sr.Close() lblDisplay.Text = LastLine End Using
Edited 1 Year Ago by Reverend Jim: corrected code formatting