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 Reading no of lines from a file Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Java » I/O and Streams
Reply Bookmark "Reading no of lines from a file" Watch "Reading no of lines from a file" New topic
Author

Reading no of lines from a file

Bindu Dharmavaram
Greenhorn

Joined: May 23, 2001
Posts: 9
Hi,
I was wondering if I can possibly read the contents of a given no of lines in a file (say 500 out of 1000 lines) into an array in a single step ? I can use the BufferedReader's readLine() in a for loop. But, is there any way to copy the contents of a given number of lines from a file to an array in one call ?
-Bindu
Jim Yingst
Wanderer
Sheriff

Joined: Jan 30, 2000
Posts: 18652
No, not that I can think of.


"I'm not back." - Bill Harding, Twister
Zakaria Haque
Ranch Hand

Joined: Jan 02, 2002
Posts: 60
Originally posted by Bindu Dharmavaram:
Hi,
I was wondering if I can possibly read the contents of a given no of lines in a file (say 500 out of 1000 lines) into an array in a single step ? I can use the BufferedReader's readLine() in a for loop. But, is there any way to copy the contents of a given number of lines from a file to an array in one call ?
-Bindu


If you are trying to minimize the number of calls to the read method of the underlying stream, just give your BufferedReader a large buffer size. Although you will be calling readLine() 500 times, depending on the buffer size the underlying stream's read method can be called as little as once.


tobe bondhu nouka bherao<br />shonabo gaan aj shara raat
 
 
subject: Reading no of lines from a file
 
Threads others viewed
bytes to char
Incompatible type issue
File splitting with Java..Help
How to retrieve data from database, using servlet or a jsp?
FileIO and mult. arrays
IntelliJ Java IDE