Q: Append Data to Word using JavatoWord API failing I'm trying to add data to Word document in my automation using JavatoWord API and Word is getting corrupted when I append the data.  Can anyone help?
import java.io.*;
import java.text.*;
import java.util.*;
import word.api.interfaces.IDocument;
import word.w2004.Document2004;
import word.w2004.Document2004.Encoding;
import word.w2004.elements.BreakLine;
import word.w2004.elements.Image;
import word.w2004.elements.ImageLocation;
import word.w2004.elements.Paragraph;
import word.w2004.elements.ParagraphPiece;

public void AppendtoWord() throws Exception 
{
  String strScrShotsFile = "C:/Test.doc/";
  String ScrShotsFile = "C:/test.png";   
  File fileScrShotsFile = new File (strScrShotsFile);
  boolean exists =  (fileScrShotsFile).exists();
  PrintWriter writer = null; 
  myDoc = new Document2004();

  if (!exists) {     
    try {
      writer = new PrintWriter(fileScrShotsFile);
      myDoc.encoding(Encoding.UTF_8); 
      myDoc.company("Comp Inc");
      myDoc.author("Test Automation Teams");
      myDoc.title("Application Automation Test Results");
      myDoc.subject("Screen Shots");                              
      myDoc.setPageOrientationLandscape();
      myDoc.addEle(BreakLine.times(2).create());// Document Header and Footer         
      myDoc.addEle(BreakLine.times(2).create()); 
      myDoc.getHeader().addEle(
        Paragraph.withPieces(
          ParagraphPiece.with("Screenshots for test case: "),
          ParagraphPiece.with( "Test" ).withStyle().bold().create()
        ).create()
      );
      myDoc.getFooter().addEle(Paragraph.with(ScrShotsFile).create());  // Images
      myDoc.addEle(BreakLine.times(1).create());
      myDoc.addEle(Paragraph.with("Test").withStyle().bgColor("RED").create());
      writer.println(myDoc.getContent());
    } catch (FileNotFoundException e) {
      e.printStackTrace();
    } finally {
      writer.close();                          
    }     
  } else {   
    PrintWriter writer1= null;
    try {
      writer1 = new PrintWriter(new FileWriter(fileScrShotsFile,true));         
      myDoc.addEle(Paragraph.with("This is Important").withStyle().bgColor("RED").create());
      writer1.println(myDoc.getContent());
    } catch (FileNotFoundException e) {
      e.printStackTrace();
    } finally {
      writer1.close();  
    }
  }

