Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

read blocks of lines from file

 
Sashi Gundoji
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I am new to java. I have a large file it contains the lines. Each line will be terminated with \n.

I do not want to read all lines at once, I would like to read some blocks of lines at once.

I really did not find a method to read specified number of lines. I found there some methods which are reading the number of bytes.

If any body know how to read please send me the source.

Thanking you

Regards,
Dimpu
 
Joe Ess
Bartender
Posts: 9280
10
Linux Mac OS X Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Have a look at Stan's answer to this question from yesterday.
 
Stan James
(instanceof Sidekick)
Ranch Hand
Posts: 8791
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It's a little clearer this time around ... you can make a String array as a "buffer" of some number of lines. Read lines into the array and process the array. Repeat until you hit end of file.

I'm curious why a buffer of 10 or 100 or 1000 lines might be better than, say, 1. Read a line, process it. Java's BufferedReader already optimizes physical disk reads with buffering very much like the string array just so we don't have to worry about such things.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic