Out.write () in java how to insert a new line

When writing to a text file in java, how do I enter values ​​in a new line

code snippet

while (rs.next()) { int sport = rs.getInt("sport"); String name = rs.getString("name"); out.write(sport + " : " + name);} 

the text file fills the value value1 value2 value3 ... etc. I want it to fill

 value1 value2 value3 . 
+4
source share
2 answers
  • If 'out' is PrintWriter, use println ().
  • If 'out' is a BufferedWriter, use newLine ().
  • If 'out' is another Writer, use write ('\ n') or add newLine directly to the line you are writing. If you need a system line separator, see System.getProperty () with a value of "line.separator".
+5
source

Very simple

out.write(sport + " : " + name + "\n");

What all.

+4
source

All Articles