在 Java 中执行 URI 命令

编程入门 行业动态 更新时间:2024-10-10 17:25:48
本文介绍了在 Java 中执行 URI 命令的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时送ChatGPT账号..

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屋!

更多推荐

[db:关键词]

本文发布于:2023-04-28 14:55:27,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1174853.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:命令   Java   URI

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!