java - 使用 java 1.4 使用默认程序打开文件

标签 java desktop-application desktop

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/

相关文章:

java - 访问导入的js文件中的Spring MVC模型数据

java - 大 O 符号,不理解类讲授

java - SQL 语句 - NullPointerException

.net - self 更新应用程序

windows - 获取屏幕的平均颜色 - Windows 7 C/C++

android - 如何将文件从 Android 设备推送到 Linux 桌面?

java - 使用反射读取对象的所有字段及其内容

java - 如何在桌面应用程序中执行JSP?

javascript - DevTools 与页面断开连接,electron

java - 在 linux 中用 java 打开一个 eml 文件