Dinesh Remje wrote:
This way of creating a FileWriter overwrites the file each time. Check out the other constructors of FileWriter. Or, preferably, open the FileWriter before the loop, then close it afterwards. A try-finally block would be best for that.