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?

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

Shyam
0
 
Igor BazarnyCommented:
Check out http://follow.sourceforge.net/
it's tail implementation in java
0
 
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?
0
Cloud Class® Course: Microsoft Windows 7 Basic

This introductory course to Windows 7 environment will teach you about working with the Windows operating system. You will learn about basic functions including start menu; the desktop; managing files, folders, and libraries.

 
Igor BazarnyCommented:
Check out RandomAccessFile then
0
 
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.
0
 
jerelwAuthor Commented:
Ok,

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
0
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.