Java桌面API不能使用网络路径? [英] Java Desktop API not working with network paths?

查看:96
本文介绍了Java桌面API不能使用网络路径?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


可能重复:

我正在尝试使用桌面API为文件启动相应的应用程序。所以我使用这个:
$ b $ pre $ if(Desktop.isDesktopSupported())
Desktop.getDesktop()。open新的文件(路径));

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

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


java.io.IOException:无法打开
文件:////MyNet/folder/image.jpg


任何一个人都知道是否有办法解决这个问题?

解决方案我相信你需要用标准的URI格式来指定文件的位置/名称 - 除了服务器之外,它接近于标准格式。查看 URI类的javadoc更多信息。
$ b


在最高级别,字符串形式的URI引用(以下简称为URI)具有语法

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

稍后:


分层URI可以根据语法进行进一步的分析

<所以URI应该看起来像下面的样子:[b] [b] [/ b] [/ b] [/ b]

  file://MyNet/folder/image.jpg 
$ b

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

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