Я пытаюсь открыть документ Word, получить его данные, не теряя его формат, вставить строку и объединить ее с документом Word, но получаю эту ошибку. Кто-нибудь знает решение? Я использую Apache POI
трассировка стека
public void mergeDocument(){
XWPFDocument document = new XWPFDocument();
XWPFParagraph paragraph = document.createParagraph();
XWPFRun run = paragraph.createRun();
FileInputStream fis = new FileInputStream("1.doc");
FileInputStream fis1 = new FileInputStream("2.doc");
// Stacktrace points out here - this is where the error points out
XWPFDocument xdoc = new XWPFDocument(OPCPackage.open(fis));
XWPFDocument xdoc1 = new XWPFDocument(OPCPackage.open(fis1));
XWPFWordExtractor extractor = new XWPFWordExtractor(xdoc);
XWPFWordExtractor extractor1 = new XWPFWordExtractor(xdoc1);
run.setText(extractor.getText() + "\n" + format.getChildren() +
extractor1.getText() + "\n" + format.getActiveDutyMilitary());
String dir="";
String filename = "final.docx";
JFileChooser chooser = new JFileChooser();
chooser.setCurrentDirectory(new java.io.File("."));
chooser.setDialogTitle("Save Directory");
chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
chooser.setAcceptAllFileFilterUsed(false);
if (chooser.showOpenDialog(null) == JFileChooser.APPROVE_OPTION) {
dir = chooser.getSelectedFile().toString() + "/";
}
FileOutputStream out = new FileOutputStream( new File(dir + filename));
document.write(out);
JOptionPane.showMessageDialog(null, "Document Saved","File Complete",JOptionPane.INFORMATION_MESSAGE);
}