Solved

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

Posted on 2002-04-02
6
223 Views
Last Modified: 2010-03-31
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?

0
Comment
Question by:jerelw
  • 3
  • 2
6 Comments
 
LVL 3

Accepted Solution

by:
shyamkumarreddy earned 50 total points
ID: 6914981
Yes Pls use Reader Object or derived of this class to ready the specific line.

Shyam
0
 
LVL 7

Expert Comment

by:Igor Bazarny
ID: 6915464
Check out http://follow.sourceforge.net/
it's tail implementation in java
0
 
LVL 3

Author Comment

by:jerelw
ID: 6916720
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
Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

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.

 
LVL 7

Expert Comment

by:Igor Bazarny
ID: 6917407
Check out RandomAccessFile then
0
 
LVL 3

Author Comment

by:jerelw
ID: 6918732
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
 
LVL 3

Author Comment

by:jerelw
ID: 6918748
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

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

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.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

This was posted to the Netbeans forum a Feb, 2010 and I also sent it to Verisign. Who didn't help much in my struggles to get my application signed. ------------------------- Start The idea here is to target your cell phones with the correct…
Are you developing a Java application and want to create Excel Spreadsheets? You have come to the right place, this article will describe how you can create Excel Spreadsheets from a Java Application. For the purposes of this article, I will be u…
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.

860 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question