Note that there are some explanatory texts on larger screens.

plurals
  1. POOpen a path with Desktop.open() from java on ubuntu (linux)
    text
    copied!<p>From my application written in java I want to open a folder, using the operating system file explorer.</p> <p>I use Desktop.open(new File(path))</p> <p>This works fine on windows, but on ubuntu 11.10 (linux) it doesn't work. Using the Desktop.open to open a file does work, both on ubuntu and windows.</p> <p>Using a step in between: File fPath=new File(fPath) and testing it with fPath.exists() and fPath.isDirectory() both gives true.</p> <p>using the Desktop.open(new File(path)) gives me this exception:</p> <pre><code>java.io.IOException: Failed to show URI:file:/and/here/the/path/I/use/ at sun.awt.X11.XDesktopPeer.launch(Unknown Source) at sun.awt.X11.XDesktopPeer.open(Unknown Source) at java.awt.Desktop.open(Unknown Source) </code></pre> <p>I was not able to test this on an apple computer yet, but I hoped the Desktop.open(new File(path)) was system independent.....</p> <p>by the way, the complete code:</p> <pre><code> Desktop desktop = null; // Before more Desktop API is used, first check // whether the API is supported by this particular // virtual machine (VM) on this particular host. if (!Desktop.isDesktopSupported()) { // show Error return; } desktop = Desktop.getDesktop(); String path = "here the path "; // by the way: I use System.getProperty("file.separator") as file seperator try { File fPath=new File(path); if(!fPath.exists()){ // show Error return; } if(!fPath.isDirectory()){ // show Error return; } desktop.open(new File(path)); } catch (IOException e) { log.severe(e.getMessage()); e.printStackTrace(); // show Error return; } </code></pre> <p>Some extra information: OS: Linux (3.0.0-16-generic - amd64)</p> <p>Java: 1.6.0_30-b12</p> <p>Java home: /opt/java/64/jre1.6.0_30</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload