在 Java 中执行 URI 命令 [英] Executing URI commands in Java

查看:35
本文介绍了在 Java 中执行 URI 命令的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Steam 允许用户启动游戏和执行许多其他操作的一种方式是使用 URI 协议,例如(来自 Valve 开发者社区):

One way that Steam lets users launch games and perform many other operations, is by using URI protocols, for example (from Valve developer community):

steam://run/ 将启动与指定 ID 对应的游戏.

steam://run/<id> will launch the game that corresponds to the specified ID.

steam://validate/ 将验证指定 ID 的游戏文件.

steam://validate/<id> will validate the game files of the specified ID.

我怎样才能让Java运行"这些?我什至不知道你怎么称呼它,即你是运行"URI,还是执行"它们,还是什么?因为大概这些 URI 没有任何要返回的内容,并且 Java 中的 URI 类没有任何与执行"它们相关的内容,但是 URL 有,但是它不起作用!

How can I get Java to 'run' these? I don't even know what you call it, i.e. do you 'run' URIs, or 'execute' them, or what? Because persumably these URIs don't have anything to return, and the URI class in Java doesn't have anything related to 'executing' them, however URL does, but it doesn't work!

我已经试过了:

...
try
{
    URI testURI = URI.create("steam://run/240");
    URL testURL = joinURI.toURL();
    // URL testURL = new URL("steam://run/240") doesn't work either
    joinURL.openConnection(); // Doesn't work
    // joinURL.openStream() doesn't work either
}
catch (MalformedURLException e)
{
    System.err.println(e.getMessage());
}
...

每个组合都会给出错误:unknown protocol: steam.

Each combination gives the error: unknown protocol: steam.

Steam 用于处理 URI 的系统肯定可以正常工作,因为例如,我可以将上述 URI 输入到 Firefox 中,它可以正常工作.

The system that Steam uses to handle the URIs is definitely working, because for example, I can type the above URI into Firefox and it works.

我永远感谢提供答案的人!

My eternal gratitude to the person who provides the answer!

谢谢

推荐答案

尝试 Desktop.browse(URI),这应该启动默认操作",这是steam:// URI,例如

URI uri = new URI("steam://store/240");
if (Desktop.isDesktopSupported()) {
    Desktop.getDesktop().browse(uri);
}

这篇关于在 Java 中执行 URI 命令的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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