Eksempel

public static void main( String[] args ){
FileWriter fw = null;
try {
fw = new FileWriter( "LineSeparators.txt" ); //$NON-NLS-1$
fw.write( "Hello World!" ); //$NON-NLS-1$
fw.write("\n");//$NON-NLS-1$
} catch ( Exception e ){
e.printStackTrace();
} finally {
if ( fw != null ) {
try { fw.close(); } catch ( Exception e ) {}
}
}
}

Løsning
Brug System.getProperty( "line.separator" ) i stedet for.

public static void main( String[] args ){
FileWriter fw = null;
try {
fw = new FileWriter( "LineSeparators.txt" ); //$NON-NLS-1$
fw.write( "Hello World!" ); //$NON-NLS-1$
fw.write( System.getProperty( "line.separator" ) ); //$NON-NLS-1$
} catch ( Exception e ){
e.printStackTrace();
} finally {
if ( fw != null ) {
try { fw.close(); } catch ( Exception e ) {}
}
}
}