Is the '\n' character always appropriate at the end of a line?

A good answer might be:

No. It is not as portable as using newLine().

Updated Example

The updated example program uses a BufferedWriter and the newLine() method. Look at the file it creates with NotePad (or other text editor). The lines of text should appear correctly (with the earlier examples they might not).

import java.io.*;
class WriteTextFile3
{
  public static void main ( String[] args ) 
  {
    String fileName = "reaper.txt" ;

    try
    {       
      BufferedWriter out = new BufferedWriter(
          new FileWriter( fileName  ) );

      out.write( "No Nightingale did ever chaunt"  );  
      out.newLine() ;
      out.write( "More welcome notes to weary bands"  );  
      out.newLine() ;
      out.write( "Of travellers in some shady haunt," );  
      out.newLine() ;
      out.write( "Among Arabian sands."  );  
      out.newLine() ;

      out.close();
    }
    catch ( IOException iox )
    {
      System.out.println("Problem writing " + fileName );
    }
  }
}

QUESTION 14:

Is close() necessary in this program?

Click Here after you have answered the question