使用Java 1.4使用默认程序打开文件 [英] Open file with default program using java 1.4

查看:93
本文介绍了使用Java 1.4使用默认程序打开文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

The Desktop.getDestop().open(File) launches the associated aplication to open the file.

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

The Desktop class is available since Java 1.6 - http://docs.oracle.com/javase/6/docs/api/java/awt/Desktop.html

如何使用1.4 Java版本执行同样的操作?

How to do the same using the 1.4 Java version?

推荐答案

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

you can use the following to open files with the default application:

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

这篇关于使用Java 1.4使用默认程序打开文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆