Solved

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

Posted on 2002-04-02
6
193 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
Comment Utility
Yes Pls use Reader Object or derived of this class to ready the specific line.

Shyam
0
 
LVL 7

Expert Comment

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

Author Comment

by:jerelw
Comment Utility
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 Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 
LVL 7

Expert Comment

by:Igor Bazarny
Comment Utility
Check out RandomAccessFile then
0
 
LVL 3

Author Comment

by:jerelw
Comment Utility
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
Comment Utility
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

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

For customizing the look of your lightweight component and making it look lucid like it was made of glass. Or: how to make your component more Apple-ish ;) This tip assumes your component to be of rectangular shape and completely opaque. (COD…
Java functions are among the best things for programmers to work with as Java sites can be very easy to read and prepare. Java especially simplifies many processes in the coding industry as it helps integrate many forms of technology and different d…
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …

762 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now