• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Reading no of lines from a file

 
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Wanderer
Posts: 18671
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
No, not that I can think of.
 
Ranch Hand
Posts: 60
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic