[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 242
  • Last Modified:

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?

0
jerelw
Asked:
jerelw
  • 3
  • 2
1 Solution
 
shyamkumarreddyCommented:
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
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
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

Featured Post

[Webinar] Cloud and Mobile-First Strategy

Maybe you’ve fully adopted the cloud since the beginning. Or maybe you started with on-prem resources but are pursuing a “cloud and mobile first” strategy. Getting to that end state has its challenges. Discover how to build out a 100% cloud and mobile IT strategy in this webinar.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now