commons-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Georg Henzler (Created) (JIRA)" <>
Subject [jira] [Created] (IO-288) Supply a ReverseFileReader
Date Tue, 18 Oct 2011 20:43:10 GMT
Supply a ReverseFileReader

                 Key: IO-288
             Project: Commons IO
          Issue Type: New Feature
          Components: Utilities
            Reporter: Georg Henzler

I needed to analyse a log file today and I was looking for a ReverseFileReader: A class that
behaves exactly like BufferedReader except that it goes from bottom to top when readLine()
is called. I didn't find it in IOUtils and the internet didn't help a lot either, e.g.
is a fairly inefficient - the log files I'm analysing is huge and it is not a good idea to
load the whole content in the memory. 

So I ended up writing an implementation myself using little memory and the class RandomAccessFile
- see attached file. It's used follows:

int blockSize = 4096; // only that much memory is needed, no matter how big the file is
ReverseFileReader reverseFileReader = new ReverseFileReader(myFile, blockSize, "UTF-8");
String line = null;
while((line=reverseFileReader.readLine())!=null) {
  ... // use the line
  if(enoughLinesSeen) {


I believe this could be useful for other people as well!

This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators:!default.jspa
For more information on JIRA, see:


View raw message