The task is to open a file or folder from a java-application. Took advice on the forum . But it turns out it does not work in Linux, because Desktop.isDesktopSupported () == false. How to make the program work on Linux too?
2 answers
Somehow:
try { if (Desktop.isDesktopSupported() && Desktop.getDesktop().isSupported(Desktop.Action.BROWSE)) { Desktop.getDesktop().browse(new URI(url)); } else { string os = System.getProperty("os.name"); if (!(os.startsWith("Mac OS")) && !(os.startsWith("Windows"))) { Runtime r = Runtime.getRuntime(); for (String b : list /* google-chrome, firefox, opera */) { Process p = r.exec(new String[]{"which", b}); InputStream is = p.getInputStream(); if (is.read() != -1) { r.exec(new String[]{b, url}); return; } } } } } catch (Throwable t) { }
|
According to the information from the oracle website, in Linux, this functionality is available only with the gnome libraries. If these libraries are not installed, the method returns false.
You can try to just run the necessary program. Sort of:
Runtime.getRuntime().exec("/usr/bin/firefox www.hashcode.ru");
|