aspose file tools*
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 EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » I/O and Streams
Bookmark "Write multiple lines to file" Watch "Write multiple lines to file" New topic
Author

Write multiple lines to file

Luis Fernandes
Greenhorn

Joined: Sep 22, 2007
Posts: 19
Hello,

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
Sheriff

Joined: Oct 27, 2005
Posts: 19538
    
  16

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.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Write multiple lines to file
 
Similar Threads
how to improve my program code ?
Writing or exporting data from database to a text file in jsp
error on get from resultset
accessing values from servlets to jsp
How to write data to a file and update the database concurrently