File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

reading files

 
kevin schmidt
Ranch Hand
Posts: 85
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 34
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 15302
6
Chrome IntelliJ IDE Mac OS X
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic