1

I am trying to read .log file with over 2000 lines from the end to the start. I can't use How to read file from end to start (in reverse order) in Java? , the file is to large. Here is my code:

BufferedReader br = null;
try{
  br = new BufferedReader(new  FileReader(dataFile.getAbsolutePath())); // the log file
}catch(FileNotFoundException FNFE){
  FNFE.printStackTrace();
}

And reading the file:

String line = null;
String lastLine = null;
while((line=br.readLine()) != null){
  lastLine = line; //setting lastLine to the last line in the file
}

Is there a butter way to get this line?

Community
  • 1
  • 1
Itsik Mauyhas
  • 3,824
  • 14
  • 69
  • 114

1 Answers1

5

You can use ReversedLinesFileReader from Apache Commons IO.

Jonas Czech
  • 12,018
  • 6
  • 44
  • 65
Hatim Khouzaimi
  • 515
  • 4
  • 11