This week's book giveaway is in the Jobs Discussion forum.
We're giving away four copies of Soft Skills and have John Sonmez on-line!
See this thread for details.
The moose likes I/O and Streams and the fly likes Write multiple lines to file Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » I/O and Streams
Bookmark "Write multiple lines to file" Watch "Write multiple lines to file" New topic

Write multiple lines to file

Luis Fernandes

Joined: Sep 22, 2007
Posts: 19

I have a query that returns all the clientes in my store

I have the following code :

this code create the file well, but only write the first client ( On line )

Can someone tell me what�s the problem ?

i know that in database i have 60 clients, because my System.out.println(resultSet.getString(1)); print the 60 clients

Obrigado desde ja !

Luis Claudio<br />MCSE ; CCNA ; SCJP 5.0
Rob Spoor

Joined: Oct 27, 2005
Posts: 19784

You need to put the opening and closing of the writer outside the loop. This way, for every iteration, you reopen the file, overwrite its contents, then close it again.

I also included a try-finally block to make sure that the writer gets closed, even if something goes wrong.

How To Ask Questions How To Answer Questions
I agree. Here's the link:
subject: Write multiple lines to file