Both previous answers are helpful. In addition I wouldn't use
bw.write("\n");
as its not working for me. Instead you can use the specific BufferedWriter method for this:
bw.newLine();
A newLine() method is provided, which uses the platform's own notion of line separator as defined by the system property line.separator. Not all platforms use the newline character ('\n') to terminate lines. Calling this method to terminate each output line is therefore preferred to writing a newline character directly.