Is there any way to tail a File like a tail -f?

Right now I'm going through the entire File from start finish and saving x rows into a Collection.

Is there any way to get the last x number of rows of a File with one method?

Who is Participating?
shyamkumarreddyConnect With a Mentor Commented:
Yes Pls use Reader Object or derived of this class to ready the specific line.

Igor BazarnyCommented:
Check out
it's tail implementation in java
jerelwAuthor Commented:
I'll check out the Reader Object.

...but will it work if I don't know the last line's number unless I open the File and read it line by line?
Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Igor BazarnyCommented:
Check out RandomAccessFile then
jerelwAuthor Commented:
The Reader Object lets me skip characters, but I still have to go through the whole file.

Only now, because it's not a BufferedReader, I don't even know how many lines I've got unless I count newLines.

The Reader Object is not a solution.

...I'll check out the RandomAccessFile Object now.
jerelwAuthor Commented:

Your answer was pretty vague, but I figured it out.

1. I got the size of the File
2. I skipped a set amount of (size - DEFAULT_TAIL_AMOUNT)
3. I then read the characters until I hit a new line
4. Finally, I send the remaining characters back to the screen.

Thank you
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.