gpt4 book ai didi

Java 桌面 API 无法使用网络路径?

转载 作者:行者123 更新时间:2023-12-01 16:10:41 30 4
gpt4 key购买 nike

Possible Duplicate:
Not possible to launch a file on a network using Java Desktop?

我正在尝试使用桌面 API 为文件启动适当的应用程序。所以我正在使用这个:

if (Desktop.isDesktopSupported()) 
Desktop.getDesktop().open(new File(path));

其中“path”是指向文件的字符串。

一切正常,直到我尝试启动驻留在网络位置(例如“\\MyNet\folder\image.jpg”)的 jpg 时,当我收到 IOException 时:

java.io.IOException: Failed to open file:////MyNet/folder/image.jpg

有人知道是否有办法解决这个问题吗?

最佳答案

我相信您需要以标准 URI 格式指定文件位置/名称 - 这接近标准格式(服务器除外)。请参阅 URI Class 的 javadoc了解更多信息。

At the highest level a URI reference (hereinafter simply "URI") in string form has the syntax

[scheme:]scheme-specific-part[#fragment]

稍后:

A hierarchical URI is subject to further parsing according to the syntax

[scheme:][//authority][path][?query][#fragment]

因此 URI 应如下所示:

file://MyNet/folder/image.jpg

其中“file://”是协议(protocol),“MyNet”是服务器,“/folder/image.jpg”是共享下的目录位置。

希望这会有所帮助。

关于Java 桌面 API 无法使用网络路径?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1359619/

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