[scala-io] efficient way to read only the last N lines of a big file

381 views
Skip to first unread message

Sawyer

unread,
Jun 5, 2013, 10:36:19 PM6/5/13
to scala-i...@googlegroups.com
Hi,
I am able to do this in Java using RandomAccessFile , is there any better ways to handle this in  scala-incubator/scala-io?

Thanks!

Sawyer

Jesse Eichar

unread,
Jun 6, 2013, 3:03:29 AM6/6/13
to scala-i...@googlegroups.com
I don't have a clean way of doing this at the moment.  You can do it with a seekable because the long traversable obtained from a seekable is random access so you can perform seekable.bytes.get(file.size - 1) to get the last byte.  But this is clearly not clean and Seekable should provide a way to read the file back to front instead of front to back.  It would be very easy to implement a ReversableLongTraversable which has a reverse method on it.

Jesse
Reply all
Reply to author
Forward
0 new messages