title: Find the associated program to open a file using Java
body: <p>I wish to open a file (lets say, a word document) from a Java application using the associated program installed on the computer (in this example, using MS Word or Open Office Writer).</p>
  
  <p>The catch is that I want to wait until this subprocess finishes, which can be done using the waitFor() method in the Process class.</p>
  
  <pre><code>String executable = findAssociatedApplicationPath(); //for example, returns "C:\\Program Files\\Microsoft Office\\Office12\\msword.exe"
  Process p = Runtime.getRuntime().exec(executable + " " + filepath);
  p.waitFor();
  </code></pre>
  
  <p>Can someone tell me how to write the findAssociatedApplicationPath() method so it returns the correct executable? Or is there another way to do this?</p>