gpt4 book ai didi

java - Desktop.getDesktop().isSupported(Desktop.Action.OPEN) 返回 true 但随后 Desktop#open(java.io.File) 抛出 "IOException: Failed to show URI"

转载 作者:行者123 更新时间:2023-11-30 06:03:13 26 4
gpt4 key购买 nike

在java中,我尝试使用Desktop.getDesktop().open(File file)打开一个文件,但它抛出IOException,尽管Desktop.getDesktop().isSupported(Desktop.Action.OPEN)表示支持该操作。我使用的是 Gnome 版本:版本:3.22.3-3。

代码片段:

    Desktop desktop = Desktop.getDesktop();
if (desktop.isSupported(Desktop.Action.OPEN))
desktop.open(file);

谁知道为什么

desktop.isSupported(Desktop.Action.OPEN)

返回真吗?我知道我可以使用“xdg-open”打开该文件,但我想了解这里发生了什么。

提前致谢!

更新:堆栈跟踪:

Caused by: java.io.IOException: Failed to show URI:file:/home/TEST_FILES/blabla.xls
at sun.awt.X11.XDesktopPeer.launch(XDesktopPeer.java:121)
at sun.awt.X11.XDesktopPeer.open(XDesktopPeer.java:84)
at java.awt.Desktop.open(Desktop.java:272)
... 55 more

更新#2: xdg-open 工作正常,打开 LibreOffice Calc 中的堆栈跟踪中提到的文件。

最佳答案

Javadoc 为公共(public): boolean 值isSupported ​(桌面.Action 操作)

Even when the platform supports an action, a file or URI may not have a registered application for the action. For example, most of the platforms support the Desktop.Action.OPEN action. But for a specific file, there may not be an application registered to open it. In this case, isSupported(Action) may return true, but the corresponding action method will throw an IOException.

关于java - Desktop.getDesktop().isSupported(Desktop.Action.OPEN) 返回 true 但随后 Desktop#open(java.io.File) 抛出 "IOException: Failed to show URI",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51857499/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com