title: PrintWriter--No Output?
body: <p>EDIT: Fixed!  Was overwriting file instead of appending to the file.</p>
  
  <p>I seem to have a bit of a problem trying to use a PrintWriter to add a "header" to a log file before use, so that my program knows that it is not just a random text file.  The field output_file refers to an argument taken by the logger initialization function to set the log file, whereas log_file is a static file field for the (global and static) logging class.  After opening the log file to check for errors, <em>there is no header.</em>  Using logging functions, also carried out by a PrintWriter, gives the correct output.  Am I doing something wrong?  (I know I am reinventing the wheel as a logging API already exists for Java, but I am working on a learning exercise.)</p>
  
  <pre><code>//After testing to make sure the file specified does not exist
  log_file=output_file; 
  output_file.createNewFile();
  PrintWriter pw=new PrintWriter(log_file);
  pw.println("**[PROGRAM_NAME Log]**");
  pw.flush();
  pw.close();
  isInitialized=true;
  </code></pre>
  
  <p>EDIT: The file is definitely writable, or the logger itself wouldn't work.  Also, for those who were wondering, the code to log something is the following (Same general method as writing the header AKA new PrintWriter(log_file);)</p>
  
  <pre><code>PrintWriter pw = new PrintWriter(log_file);
  pw.print("[INFO:] " + sdf.format(new Date())); //The variable sdf is a date formatter for timestamps.
  pw.println(" " + message);
  pw.close();
  </code></pre>