First you need download Apache POI - the Java API for Microsoft Documents, and next this fragment of code
public void generateDoc(String text,int size, File file) throws Exception {
XWPFDocument document = new XWPFDocument();
XWPFParagraph tmpParagraph = document.createParagraph();
XWPFRun tmpRun = tmpParagraph.createRun();
tmpRun.setText(text);
tmpRun.setFontSize(size);
document.write(new FileOutputStream(file));
}