Desktop.getDestop().open(File) 启动关联的应用程序来打开文件。
Desktop 类自 Java 1.6 起可用 - http://docs.oracle.com/javase/6/docs/api/java/awt/Desktop.html
如何使用 1.4 Java 版本执行相同操作?
最佳答案
您可以使用以下命令通过默认应用程序打开文件:
/* build up command and launch */
String command = "";
String file = "FILE IN HERE";
if (isLinux()) {
command = "xdg-open " + file;
} else if (isWindows()) {
command = "cmd /C start " + file;
} else
return;
try {
Runtime.getRuntime().exec(command);
} catch (Exception ex) {
ex.printStackTrace();
}
自 1.0 起可用:Runtime .
关于java - 使用 java 1.4 使用默认程序打开文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11106424/