Saltos de línea

En sistemas tipo UNIX, Linux, ...

“línea 1” + “n” + “línea 2”

 

En sistemas tipo Windows

“línea 1” + “rn” + “línea 2”

 

Si queremos que el código se adapte al sistema en el que ejecuta

String LS = System.getProperty("line.separator");

“línea 1” LS + “línea 2”

o

String.format(“%s%n%s”, “línea 1”, “línea 2”);

 

Si estamos escribiendo en un fichero, también podemos hacerlo directamente:

writer.print(“línea 1”);

writer.println();

writer.print(“línea 2”);

o

writer.println(“línea 1”);

writer.println(“línea 2”);

Temas relacionados

36. String (clase) java.lang.String