It's not a secret anymore!
The moose likes Beginning Java and the fly likes Reading a file in reverse order Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Reading a file in reverse order" Watch "Reading a file in reverse order" New topic

Reading a file in reverse order

sambasivarao laghuvarapu

Joined: Jun 07, 2007
Posts: 9
Hi All,

How to read the file using BufferedReader in reverse oreder.
please give the example code.

Ankit Garg

Joined: Aug 03, 2008
Posts: 9462

There are two choices for this.

either you read the content of the whole file into a StringBuffer (via a String) and then reverse the StringBuffer.

The second option is to read the file one character at a time in reverse order with the help of RandomAccessFile object which is not in the objectives of SCJP so I don't think it must be discussed here....

SCJP 6 | SCWCD 5 | Javaranch SCJP FAQ | SCWCD Links
I agree. Here's the link:
subject: Reading a file in reverse order
jQuery in Action, 3rd edition