rocket mass heater kickstarter
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 Barcodes with iOS this week in the iOS forum
or Core Java for the Impatient in the Java 8 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: 19896

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