1

I'm using Java with Apache POI to create a word document based on an ArrayList. Everything works, except that I want that the specific Word document opens itself after it is created. Does anyone know a method or simply how I can achieve this

try{
        FileOutputStream outStream = new 
        FileOutputStream("CarteBoissons.docx");
        XWPFDocument doc = new XWPFDocument();
        XWPFParagraph paraTit = doc.createParagraph();
        XWPFRun paraTitRun = paraTit.createRun();
        paraTitRun.setBold(true);
        paraTitRun.setFontSize(20);
        paraTitRun.setText("CARTE BOISSONS" +
                "" +
                "" +
                "");
 doc.write(outStream);
        outStream.close();
        JOptionPane.showMessageDialog(null, "Le document Word a été créé");
    }catch(Exception e){
        JOptionPane.showMessageDialog(null, e);
    }
Nondikass
  • 21
  • 8

1 Answers1

2

If I understand correctly you wanted something like this

Desktop.getDesktop().open(new File("path to your word file"));

Use this in your code when you want to open the file with your default application

Deb
  • 2,922
  • 1
  • 16
  • 32