Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

How to output result set into individual text file?  RSS feed

 
kelvin Seow
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I am able to return result set from query into text file but i want it once it query it auto save into a new file instead of creating all in one text file.

It have 5 return result but its all save inside 1 text file which i want it to be in 5 text file.

Here is my code.


 
Junilu Lacar
Sheriff
Posts: 11132
160
Android Debian Eclipse IDE IntelliJ IDE Java Linux Mac Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Then you'd need to move lines 16 and 18 inside the loop and update the count variable as you go, right? Your current code creates only one BufferedWriter so that's why everything is getting written to just that one file.

Be sure to adjust where you're closing your I/O resources as well.
 
kelvin Seow
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Junilu Lacar,

Do you mean like this?

 
kelvin Seow
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi ,

I realize my mistake my count was inside that why it could generate 5 files out. Thanks for the help Juilan

by the way since my folder have 5 files how do i do a loop to look through that folder for all the 5 files?

 
Junilu Lacar
Sheriff
Posts: 11132
160
Android Debian Eclipse IDE IntelliJ IDE Java Linux Mac Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
kelvin Seow wrote:Do you mean like this?

Close, but there's still a mistake there. At the start of each iteration of the loop, you set count to 0. That will make your code always output to a SQLRetrieve0.txt file, no matter how many iterations you have.

I suggest you look through the API documentation for java.nio.file.Files and java.nio.file.DirectoryStream. There are examples in the latter that will answer your other question.

kelvin Seow wrote:Thanks for the help Juilan

You're welcome, but it's Junilu, not Juilan
 
kelvin Seow
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Junilu,

Sorry for the mistake. Oh 1 more question how do i loop through a folder which contains the 5 file?
 
Junilu Lacar
Sheriff
Posts: 11132
160
Android Debian Eclipse IDE IntelliJ IDE Java Linux Mac Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please read the suggestion in my previous response carefully. Thanks.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!