title: create new document from template
body: <p>I want to open a new document from a MS-Word template from my Java-App, but only manage to edit the template itself.</p>
  
  <p>Here is my situation:
  Inside my Jar file is a word template, that gets copied to a user-specified location, so he/she can edit it. Afterwards, the application can open this edited template, insert data into it and open it in word. This all works fine (using Apache-POI), but the last step is not entirely what I want.</p>
  
  <p>Normally, when double-clicking a word-template, Word would open a NEW document (titled Document1) that is not saved anywhere yet. In my case, Word opens the word-template for editing (titled blablaMyTemplate), meaning the already saved template from which documents should be created. How do I manage to open a newly created document from the template using Java?</p>
  
  <p>This is my code (try/catch and stream closing omitted):</p>
  
  <pre><code>    File bbb = new File(new File(getClass().getProtectionDomain().getCodeSource().getLocation().toURI().getPath()).getParentFile().getParentFile().getAbsolutePath() + "/blablaMyTemplate.dotx");
      if (!bbb.exists()) { //copy file to outside of jar for user editing
          Files.copy(Buchungsbegleitblatt.class.getResourceAsStream("bbb.dotx"), bbb.toPath(), StandardCopyOption.REPLACE_EXISTING);
      }
      File tmp = File.createTempFile("bbb", ".dotx"); //create tmp file to insert data
      InputStream in = new FileInputStream(bbb);
      OutputStream out = new FileOutputStream(tmp);
      XWPFDocument document = new XWPFDocument(in);
      //here, some data is filled into the document using Apache-POI (omitted, because it works fine)
      document.write(out);
      if (Desktop.isDesktopSupported()) {
          Desktop.getDesktop().open(tmp); //this opens the template for editing, it does not create a new doc from template
      }
  </code></pre>
  
  <p>The issue lies within the last line, but I have no idea what else I could call here.</p>
  
  <p>To make it a little clearer, here is an image of the context menu I get on the template file and what is supposed to happen:</p>
  
  <p><a href="https://i.stack.imgur.com/OhnLI.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/OhnLI.png" alt="context menu on template"></a></p>