title: Java: Open a file (Windows + Mac)
body: <blockquote>
    <p><strong>Possible Duplicate:</strong><br>
    <a href="https://stackoverflow.com/questions/560077/how-to-launch-the-default-native-application-for-a-given-file-from-java">How to launch the default (native) application for a given file from Java?</a>  </p>
  </blockquote>
  
  
  
  <p>I have a java application that opens a file. This works perfect on windows, but not on mac. </p>
  
  <p>The problem here is that I use the windows configuration to open it. The code is:</p>
  
  <p><code>Runtime.getRuntime().exec("rundll32 url.dll,FileProtocolHandler " + file);</code></p>
  
  <p>Now my question is what is the code to open it in mac? Or is there another way to open a PDF that works multi platform?</p>
  
  <p><strong>EDIT:</strong> </p>
  
  <p>I created the file as followed:</p>
  
  <pre><code>File folder = new File("./files");
  File[] listOfFiles = folder.listFiles();
  </code></pre>
  
  <p>in a loop i add them to an array:</p>
  
  <p><code>fileArray.add(listOfFiles[i]);</code></p>
  
  <p>If i try to open a file from that array with Desktop.getDesktop().open(file), it says it can't find that file (the path is messed up because I used './files' as folder)</p>