This week's book giveaway is in the Jython/Python forum.
We're giving away four copies of Murach's Python Programming and have Michael Urban and Joel Murach on-line!
See this thread for details.
Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

any way to go to the end of a file and move backwards  RSS feed

 
Anoop Nath
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In java is there any way to go to the end of the file and then move backwards?
 
Gary McGath
Ranch Hand
Posts: 52
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
(In java is there any way to go to the end of the file and then move backwards? )
Certainly, but you have to do a little work. Create a RandomAccessFile object and call pos = RandomAccessFile.length() to get the end position. The simplest implementation would call seek(--pos) and then read() to get each byte; this is OK if you don't care about efficiency. A better way would be to read a buffer at a time and pull bytes out from end to start.
With a little more work, you could wrap this up in a BackwardsInputStream class that provided you with a read() method which would get bytes in reverse order.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!