I have the following code to print a string(from a ResultSet) to a text file:
PrintWriter writer = new PrintWriter(new FileOutputStream(file, false));
while(
You can use PrintWriter#println() method instead.
From API:
Terminates the current line by writing the line separator string. The line separator string is defined by the system property line.separator, and is not necessarily a single newline character ('\n').
Also this should work as well.
writer.write(RS.getString(1)+ System.getProperty("line.separator"));