Java桌面API不能使用网络路径? [英] Java Desktop API not working with network paths?
问题描述
我正在尝试使用桌面API为文件启动相应的应用程序。所以我使用这个:
$ b $ pre $ if(Desktop.isDesktopSupported())
Desktop.getDesktop()。open新的文件(路径));
其中path是指向文件的字符串。
一切正常,直到我尝试启动驻留在网络位置的jpg(例如\\MyNet\folder\image.jpg),当我得到一个IOException:
java.io.IOException:无法打开
文件:////MyNet/folder/image.jpg
任何一个人都知道是否有办法解决这个问题?
$ b
在最高级别,字符串形式的URI引用(以下简称为URI)具有语法
[scheme:] scheme-specific-part [#fragment]
稍后:
分层URI可以根据语法进行进一步的分析
<所以URI应该看起来像下面的样子:[b] [b] [/ b] [/ b] [/ b]$ bfile://MyNet/folder/image.jpg
其中file://是协议,MyNet是服务器,/folder/image.jpg是共享下的目录位置。 / p>
希望这会有所帮助。
Possible Duplicate:
Not possible to launch a file on a network using Java Desktop?I am trying to use the Desktop API to launch the appropriate app for a file. So i am using this :
if (Desktop.isDesktopSupported()) Desktop.getDesktop().open(new File(path));
where "path" is a String pointing to the file.
Everything works fine until i try to launch a jpg that resides at a network location (for instance "\\MyNet\folder\image.jpg") when i get an IOException :
java.io.IOException: Failed to open file:////MyNet/folder/image.jpg
Any one knows if there is a way to fix this?
解决方案I believe you need to specify the file location/name in standard URI format - which is close to the standard format except for servers. See the javadocs for the URI Class for more information.
At the highest level a URI reference (hereinafter simply "URI") in string form has the syntax
[scheme:]scheme-specific-part[#fragment]
And a little later:
A hierarchical URI is subject to further parsing according to the syntax
[scheme:][//authority][path][?query][#fragment]
so the URI should look something like the following:
file://MyNet/folder/image.jpg
where "file://" is the protocol, "MyNet" is the server, and "/folder/image.jpg" is the directory location under the share.
Hope this helps a little.
这篇关于Java桌面API不能使用网络路径?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!