I am using Apache POI to create header and footer but the resulting file cannot be opened. [1]: https://i.stack.imgur.com/eDGcF.png
XWPFDocument docx = new XWPFDocument();
CTP ctpFooter = CTP.Factory.newInstance();
ctpFooter.addNewR().addNewT();
XWPFParagraph footerParagraph = new XWPFParagraph(ctpFooter, docx);
XWPFRun footerRun = footerParagraph.createRun();
footerRun.setFontSize(6);
footerRun.setText("footerText");
XWPFParagraph[] parsFooter = new XWPFParagraph[1];
parsFooter[0] = footerParagraph;
CTSectPr sectPr = docx.getDocument().getBody().addNewSectPr();
XWPFHeaderFooterPolicy policy = new XWPFHeaderFooterPolicy(docx, sectPr);
policy.createFooter(XWPFHeaderFooterPolicy.DEFAULT, parsFooter);
FileOutputStream out = new FileOutputStream("E:/docx/write-test.docx");
docx.write(out);
out.close();