Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

reading last line of file  RSS feed

 
Lukas Alamar
Ranch Hand
Posts: 68
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Howdy all, does anybody know if there's a way to read the last line of a text file without having to loop over each line using BufferReader's readLine method?

thanks
 
sreedhara satuluri
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
there are no such functionalities in the streams.
if you gret from any source then please let me also know
 
Stan James
(instanceof Sidekick)
Ranch Hand
Posts: 8791
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
For fun you might open a random access file and read characters from the last one backwards until you hit newline or start of file. It would be interesting to compare this to the 'read every line' alternative you mentioned for various file sizes. I suppose you could read more than one character at a time into a 'buffer' and search for the newline in the buffer. I'm not at all sure this would be worth doing.
 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!