aspose file tools*
The moose likes Beginning Java and the fly likes reading files Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "reading files" Watch "reading files" New topic
Author

reading files

kevin schmidt
Ranch Hand

Joined: Aug 24, 2001
Posts: 85
Hi,
How does a person go about reading in a text file starting from the end instead of the beginning of it? TIA.
Kevin
Martin Rennix
Ranch Hand

Joined: Sep 30, 2001
Posts: 34
At a guess, try java.io.RandomAccessFile and use seek() to go to the end of the file. You'll need to use seek() to move further back into the file after each read(). Remember seek() uses bytes so if you are reading Unicode chars using readChar() you'll need to move 4 bytes back (the 2 bytes you have just read plus another 2 to go the previous char.)
I hope that makes sense!
Martin
Gregg Bolinger
GenRocket Founder
Ranch Hand

Joined: Jul 11, 2001
Posts: 15286
    
    6

Another way is you could read the file beginning to end into an array, then just step through the array backwards while doing the work you need to do in the file.

------------------
Happy Coding,
Gregg Bolinger


GenRocket - A Test Data Generation Platform
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: reading files
 
Similar Threads
How did you learn?
instance variables
This needs a better caption.
Place Association
change back text of button with help of Thread.sleep()