File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
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

Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
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: 9280

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
Similar Threads
Can FOP (Apache) translate a PDF back into ".fo"?
Listeners question
calling a button from utility file
WA #1.....word association