title: Create html file and add rows dynamically
body: <p>I wanted to create log.html file using java wherein i'll dump errors into html table-row as and when errors are caught.
  I created table columns but when i am passing anything to it then my data is overwriting column names instead of appending row.
  My java code is as follows:</p>
  <pre><code>public static void main(String[] args) throws IOException
  {
      String month = getMonth(1);
      System.out.println(month);
      //table(month);
      addrow(&quot;abc&quot;);
  }
  public static void table(String Update) throws IOException
  {
      //define a HTML String Builder
      StringBuilder htmlStringBuilder=new StringBuilder();
      htmlStringBuilder.append(&quot;&lt;html&gt;&lt;head&gt;&lt;title&gt;Packaging Issues&lt;/title&gt;&lt;/head&gt;&quot;);
      htmlStringBuilder.append(&quot;&lt;body&gt;&lt;h1&gt; Files Received &lt;/h1&gt;&quot;);
      htmlStringBuilder.append(&quot;&lt;table border=\&quot;1\&quot; bordercolor=\&quot;#000000\&quot;&gt;&quot;);
      htmlStringBuilder.append(&quot;&lt;tr&gt;&lt;td&gt;&lt;b&gt;Cycle&lt;/b&gt;&lt;/td&gt;&lt;td&gt;&quot;+Update+&quot;&lt;/td&gt;&lt;/tr&gt;&quot;);
      htmlStringBuilder.append(&quot;&lt;tr&gt;&lt;td&gt;&lt;b&gt;Version&lt;/b&gt;&lt;/td&gt;&lt;td&gt;&lt;/tr&gt;&quot;);
      newtable(htmlStringBuilder.toString());
  }
  public static void newtable(String a)
  {
      StringBuilder htmlStringBuilder=new StringBuilder();
      htmlStringBuilder.append(a);
      htmlStringBuilder.append(&quot;&lt;h1&gt; Issues Found &lt;/h1&gt;&quot;);
      htmlStringBuilder.append(&quot;&lt;table border=\&quot;1\&quot; bordercolor=\&quot;#000000\&quot;&gt;&quot;);
      htmlStringBuilder.append(&quot;&lt;tr&gt;&lt;td&gt;&lt;b&gt;Type&lt;/b&gt;&lt;/td&gt;&quot;);
      htmlStringBuilder.append(&quot;&lt;td&gt;&lt;b&gt;Field&lt;/b&gt;&lt;/td&gt;&quot;);
      htmlStringBuilder.append(&quot;&lt;td&gt;&lt;b&gt;Issue&lt;/b&gt;&lt;/td&gt;&lt;/tr&gt;&quot;);
      addrow(htmlStringBuilder.toString());
       // WriteToFile(htmlStringBuilder.toString(),&quot;log.html&quot;);
  }
  
  public static void addrow(String a)
  {
      try {
          StringBuilder htmlStringBuilder=new StringBuilder();
          htmlStringBuilder.append(&quot;&lt;tr&gt;&lt;td&gt;&lt;b&gt;&quot;+a+&quot;&lt;/b&gt;&lt;/td&gt;&quot;);
          htmlStringBuilder.append(&quot;&lt;td&gt;&lt;b&gt;Field&lt;/b&gt;&lt;/td&gt;&quot;);
          htmlStringBuilder.append(&quot;&lt;td&gt;&lt;b&gt;Issue&lt;/b&gt;&lt;/td&gt;&lt;/tr&gt;&quot;);
          htmlStringBuilder.append(&quot;&lt;/table&gt;&lt;/body&gt;&lt;/html&gt;&quot;);
          WriteToFile(htmlStringBuilder.toString(),&quot;log.html&quot;);
      } catch (IOException e) {
          e.printStackTrace();
      }
  }
  </code></pre>
  <p>Here's the writetofile method:</p>
  <pre><code>  public static void WriteToFile(String fileContent, String fileName) throws IOException {
      String projectPath = &quot;/home/abc&quot;;
      String tempFile = projectPath + File.separator+fileName;
      File file = new File(tempFile);
      // if file does exists, then delete and create a new file
            //write to file with OutputStreamWriter
      OutputStream outputStream = new FileOutputStream(file.getAbsoluteFile());
      Writer writer=new OutputStreamWriter(outputStream);
      writer.write(fileContent);
      writer.close();
  
  }
  </code></pre>