1

Desktop.getDestop().open(File) 启动关联的应用程序以打开文件。

Desktop 类从 Java 1.6 开始可用 - http://docs.oracle.com/javase/6/docs/api/java/awt/Desktop.html

如何使用 1.4 Java 版本做同样的事情?

4

2 回答 2

1

您可以使用以下命令使用默认应用程序打开文件:

    /* 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 开始可用:运行时

于 2012-06-19T17:50:24.960 回答
0

Runtime.exec()

可以在以下位置找到更多详细信息:http: //docs.oracle.com/javase/6/docs/api/java/lang/Runtime.html

于 2012-06-19T17:50:05.850 回答