aspose file tools*
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
Author

Reading a file in reverse order

sambasivarao laghuvarapu
Greenhorn

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

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

Thanks.
Ankit Garg
Sheriff

Joined: Aug 03, 2008
Posts: 9313
    
  17

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: http://aspose.com/file-tools
 
subject: Reading a file in reverse order