title: Adding The Date and Time to the File name
body: <p>Hello I am trying to add the date and time to a file name in JAVA. I can get the date and time printed within the file, which I also want done, but when I place the toString in the FileWriter I get a Null Pointer. </p>
  
  <pre><code>package com.mkyong;
  import java.util.*;
  import java.io.*;
  import java.*;
  import java.util.Date;
  import java.text.DateFormat;
  import java.text.SimpleDateFormat;
  
      public class Simplex {
  
          private static PrintWriter outFile;
  
          //Main Method
          public static void main(String[] args) throws IOException {
  
  
  
              // Instantiate a Date object
               Date date = new Date();
  
               // display time and date using toString()
               outFile.println(date.toString());
               outFile.println();
              //creates the new file to be saved
  
  
              outFile = new PrintWriter(new FileWriter("simplex" + (date.toString()) + ".txt"));
  </code></pre>