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.
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.