Writing a text file using FileWriter

Main.java:

import java.io.*;
 
public class Main
{
   public static void main(String []args) {
      String lineSeparator = System.getProperty("line.separator");
      StringBuffer sb = new StringBuffer();
      sb.append("Hello");
      sb.append(lineSeparator);
      sb.append("World!");
      sb.append(lineSeparator);
 
      try {
         BufferedWriter bw = new BufferedWriter(new FileWriter("textfile.txt"));
         bw.write(sb.toString());
         bw.close();
      } 
      catch(IOException e) {
         e.printStackTrace();
      }
   }
}