File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes I/O and Streams and the fly likes read blocks of lines from file Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » I/O and Streams
Bookmark "read blocks of lines from file" Watch "read blocks of lines from file" New topic
Author

read blocks of lines from file

Sashi Gundoji
Greenhorn

Joined: Jan 30, 2007
Posts: 10
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

Joined: Oct 29, 2001
Posts: 8836
    
    7

Have a look at Stan's answer to this question from yesterday.


"blabbing like a narcissistic fool with a superiority complex" ~ N.A.
[How To Ask Questions On JavaRanch]
Stan James
(instanceof Sidekick)
Ranch Hand

Joined: Jan 29, 2003
Posts: 8791
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.


A good question is never answered. It is not a bolt to be tightened into place but a seed to be planted and to bear more seed toward the hope of greening the landscape of the idea. John Ciardi
 
jQuery in Action, 2nd edition
 
subject: read blocks of lines from file
 
Similar Threads
What is the Best way to determine # of line in a...
Skipping to a particular line while reading Text File
Find last line number in a file
Accessing a File
Reading no of lines from a file