Skip to Main Content

Java Programming

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Determining number of lines in a File without loading it to memory

807580Nov 30 2009 — edited Dec 1 2009
hello guys,

I'm just wondering if there is a way to know the number of lines in a file without having to load the file entirely into memory and count the lines.
in my project i have a restriction that says that i'm not allowed to load into memory more than 10 KB. i have to read the file block by block, say ten lines at a time.
I actually did the second point which is reading the file 10 lines at a time, but still the total number of lines is still hard coded.

thank you for your help !
I
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Dec 29 2009
Added on Nov 30 2009
16 comments
469 views