xsunil kumar wrote:I will try to debug your program. But i have one more idea. If you are using Linux, then there is a command to split the file. Exactly i do not remember the command. You can get that on google.
Stefaan Dutry wrote:when you create a BufferedWriter using a FileWriter you shouldn't close the FileWriter anymore.
Closing the BufferedWriter automaticaly closes the Filewriter too then (decorator pattern).
If you read Buffered Writer javadoc for close() method you will see why it could fail when you close the FileWriter ( see the description).
If you have more questions,
Stefaan Dutry wrote:think i spotted the real problem now
you're only closing and thereby flushing the buffered writer once and not each time you make a new one => possibly having characters in your buffer not yet written when you make a new one and losing them
Campbell Ritchie wrote:More seriously, you are setting the writers to null. Don't do that; when you have finished with a writer (or a reader) you should close it, preferably in a finally block.
Why don't you use the more modern tools, Scanner and Formatter?
Why on earth are you mixing database connectivity and text file writing in the same method?
I don't think your thread.sleep call helps at all. It probably does nothing except delay execution.
Jesper de Jong wrote:In general, methods should have a single purpose or single responsibility (see Single responsibility principle - this not only applies to classes, as the article says, but to methods as well). There are a number of good books on object oriented design. One of the most famous books is Clean Code: A Handbook of Agile Software Craftsmanship by Robert C. Martin ("Uncle Bob").
When you do JDBC stuff and writing to a file in one method, then you're mixing two APIs that both require a fair amount of boiler plate code and exception handling, and putting all that stuff in one method will make it complicated and hard to follow.
It's not so that it should not absolutely never be done that way, but there are ways to structure your code differently so that it is easier to read and maintain.