• 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

Writing to multiple file

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi All,

I have a program that reads data from the database and writes into a csv file. I wants to write to multiple files instead of single file.
If the databse table contains 40 records then it should create 4 files with 10 record in each file.
Could anyone guide me in this regard.

The code i have is as below which reads data from database and writes all the record to a single file:-



 
Bartender
Posts: 3648
16
Android Mac OS X Firefox Browser Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

cheers justin wrote:Hi All,

I have a program that reads data from the database and writes into a csv file. I wants to write to multiple files instead of single file.
If the databse table contains 40 records then it should create 4 files with 10 record in each file.
Could anyone guide me in this regard.



Welcome to the ranch. You will need a variable keeping track of the number of rows read from the database. Once this reaches 10, new File(...)

And this will also mean you need to generate the file's name. From your existing posted code, lines 11 to 15 will eventually be inside the while loop (line 20). Remember to close each file too (line 45) inside the while loop.
reply
    Bookmark Topic Watch Topic
  • New Topic