you can use writer.newline()
and writer.flush() can be removed, this is not a bufferedwriter