import java.io.PrintWriter;
import java.io.IOException;

public class WriteToFile {
   public static void main(String[] args) {
      try {
         PrintWriter writer = new PrintWriter("ThisFile.txt");
         writer.println("Line 1");
         writer.println("Line 2");
         writer.flush();
         writer.println("Line 3");
         // add call to writer.flush() to see line 3 in the
         //    output file
      }
      catch ( IOException ioe ) { 
         System.err.println("Error: cannot write to ThisFile.txt");
         System.exit(1);
      }
   }
}
