我正在编写一个应用程序。当满足某些要求时,应用程序必须打开 Firefox。我做了一个小研究。我能找到的只是以下代码。
Runtime rt = null;
rt = Runtime.getRuntime();
try {
rt.exec("C:\\Program Files (x86)\\Google\\Chrome\\Application\\chrome.exe google.com");
} catch (IOException e) {
e.printStackTrace();
}
我想知道的是,在不给出路径的情况下打开特定应用程序的任何方法,因为所有用户都不会在同一路径中安装该应用程序。就像只用名字搜索一样。请帮忙。提前致谢。
最佳答案
您可以使用Desktop
类,了解更多详细信息doc here
URI uri = null;
try {
uri = new URI("http://www.google.com");
desktop.browse(uri);
} catch(IOException ioe) {
System.out.println("The system cannot find the " + uri +
" file specified");
//ioe.printStackTrace();
} catch(URISyntaxException use) {
System.out.println("Illegal character in path");
//use.printStackTrace();
}
关于java - 从java代码打开应用程序而不指定路径,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25765302/