Forums Register Login

Reading no of lines from a file

+Pie Number of slices to send: Send
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
+Pie Number of slices to send: Send
No, not that I can think of.
+Pie Number of slices to send: Send
 

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.
It would give a normal human mental abilities to rival mine. To think it is just a tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com


reply
reply
This thread has been viewed 934 times.
Similar Threads
FileIO and mult. arrays
How to retrieve data from database, using servlet or a jsp?
File splitting with Java..Help
bytes to char
Incompatible type issue
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 28, 2024 14:45:37.