Java writing to a text file not working properly
<p>The Java application that I support is logging some details in a flat file. the problem I face  some times is that, the entry is very low compared to the previous day. This entry is most essential because our reports are generated based on the file. I went thro code for writing I couldn't figure out any issues. the method which is writing is sync method. </p>

<p>Any suggestions? I can also provide the code for you is you may need? </p>

<pre><code> public synchronized void log (String connID, String hotline, String callerType,
        String cli, String lastMenu, String lastInput,
        String status, String reason)
   {
    //String absoluteFP = LOG_LOC + ls + this.getFilename();

    //PrintWriter pw = this.getPrintWriter(absoluteFP, true, true);

    try
    {
        pw.print (this.getDateTime ()+ ","+connID +","+hotline+","+callerType+","+ cli+"," +   lastMenu + "," + lastInput + "," + status + "," + reason);               


        //end 1006
        pw.print (ls);
        pw.flush ();
        //pw.close();
    }
    catch (Exception e)
    {
        e.printStackTrace ();
        return;
    }
}

private synchronized PrintWriter getPrintWriter (String absoluteFileName,
        boolean append, boolean autoFlush)
{
    try
    {
        //set absolute filepath
        File folder = new File (absoluteFileName).getParentFile ();//2009-01-23

        File f = new File (absoluteFileName);

        if (!folder.exists ())//2009-01-23
        {
            //System.out.println ("Call Detailed Record folder NOT FOUND! Creating a new);     
            folder.mkdirs ();

            //System.out.println ("Configure log folder");
            this.setHiddenFile (LOG_LOC);//set tmp directory to hidden folder

            if (!f.exists ())
            {
                //System.out.println ("Creating a new Call Detailed Record...");//2009-01-23

                f.createNewFile ();//2009-01-23

                               }
        }
        else
        {
            if (!f.exists ())
            {
                //System.out.println ("Creating a new Call Detailed Record...");//2009-01-23

                f.createNewFile ();//2009-01-23


            }
        }

        FileOutputStream tempFOS = new FileOutputStream (absoluteFileName, append);
        if (tempFOS != null)
        {
            return new PrintWriter (tempFOS, autoFlush);
        }
        else
        {
            return null;
        }
    }
    catch (Exception ex)
    {
        ex.printStackTrace ();
        return null;
    }
}

          /**
             * Set the given absolute file path as a hidden file.
        * @param absoluteFile String
      */
     private void setHiddenFile (String absoluteFile)
       {
    //set hidden file
    //2009-01-22, KC
    Runtime rt = Runtime.getRuntime ();
    absoluteFile = absoluteFile.substring (0, absoluteFile.length () - 1);//2009-01-23
    try
    {
      System.out.println (rt.exec ("attrib +H " + "\"" + absoluteFile +        "\"").getInputStream ().toString ());
    }
    catch (IOException e)
    {
        e.printStackTrace ();
    }
}

private String getDateTime ()
{
    //2011-076-09, KC-format up to milliseconds to prevent duplicate PK in CDR table.
    //return DateUtils.now ("yyyy/MM/dd HH:mm:ss");
    return DateUtils.now ("yyyy/MM/dd HH:mm:ss:SSS");
    //end 0609
}

private String getFilename ()
{
    ///return "CDR_" + port + ".dat";//2010-10-01
    return port + ".dat";//2010-10-01
}

public void closePW ()
{
    if (pw != null)
    {
        pw.close ();
    }
}
</code></pre>
