3 Replies Latest reply: Feb 13, 2008 5:30 AM by 800322 RSS

    Appending data to file

    807601
      Hi,

      Im trying to append data to a file. For some reason the data is not being writing to the file at all.

      Here's my class : Im call the logError method. Is something wrong here?

      public class ErrorLog
      {
           
           File error_file;
      FileOutputStream error_fout;
      PrintStream error_p;
      StringBuffer error_data;
      //String error_data = "";

      boolean append = true;
      FileWriter fw = null;

      public ErrorLog(String filename)throws FileNotFoundException,IOException
      {
           
      //error_file = new File(filename);
      fw = new FileWriter(filename,append);

           
      }


      public void logError(int errorCode,String msg)throws IOException
      {

           
      error_data.append(cur_timestamp() + " " + errorCode + " " + msg);
      fw.write(error_data.toString());//appends the string to the file
      error_data.setLength(0);     

           
      }

      private Timestamp cur_timestamp()
      {
           
      Timestamp sqlDate = new Timestamp(new Date().getTime());
           
      return sqlDate;
      }

      public void closeError() throws IOException
      {
           if (fw != null)
           {
      fw.close();
      }

      }
           
      }


      Thanks
      Rebekah