• 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 File in Chunks

 
Ranch Hand
Posts: 324
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Rancher

I have a File object that is representing a CSV file. I want to read that file in chunks e.g say first time i read 50 records and next time i want to jump at 51st record and read next till 100th. Is there any way to access the file data randomly. Please help

Thanks
 
(instanceof Sidekick)
Posts: 8791
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
There is a RandomAccessFile in the JDK, but it will only read "records" conveniently if they are all the same length. If you can pad fields and/or records to a fixed length, it will work great. Otherwise, probably not what you need.

Do you need to close the file between chunks? If not, you can just read 50 lines, leave the file open while you do something else, read 50 more and so on. If yes, you might try to compute how many bytes you have read in the first chunk, close the file while you do something else, open it again and Reader.skip() that many bytes before reading more. The only tricky bit there might be counting CR and/or LF characters ... linends are not always the same size.

Any of that sound useful?
[ March 08, 2007: Message edited by: Stan James ]
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic