• Post Reply Bookmark Topic Watch Topic
  • New Topic

Writing to multiple file

 
cheers justin
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • 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:-



 
K. Tsang
Bartender
Posts: 3610
16
Firefox Browser Java Mac OS X
  • Mark post as helpful
  • send pies
  • 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.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!