title: How can I write a string to a .html file?
body: <p>I am creating a HTML Webpage Generator as part of a college assignment. What I am trying to do is set the header by taking in the users text and saving it to string through the use of a get / set class. However when I try to output the text to file I get an error.</p>
  
  <p>The code I am using to try and output the string is the following</p>
  
  <pre><code>public static void main(String[] args) throws IOException { 
          try { 
              File f = new File("C:\\Users\\David\\Desktop\\output.html");
              if(!f.exists()) { 
                  f.createNewFile();
              }
              FileWriter fw = new FileWriter(f);
              fw.write(getHeader());
              fw.close();
          }catch(IOException io) { 
              Logger.getLogger(webPage.class.getName()).log(Level.SEVERE, null, io);
          }
      }
  </code></pre>
  
  <p>The error that Eclipse is giving me is </p>
  
  <pre><code>Exception in thread "main" java.lang.NullPointerException
      at java.io.Writer.write(Unknown Source)
      at webPage.main(webPage.java:49)
  </code></pre>
  
  <p>Can anyone help me correct this please? </p>