0

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?

0

4 Answers 4

1

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.

Sign up to request clarification or add additional context in comments.

5 Comments

The main problem being that your URI has four slashes after the file:, while it should only have 2
I'm sorry - I am not sure which edits you are talking about.
:D i deleted them and created a dupe. :D check out the comment to find it and vote this closed. Thanks for your answer btw. i voted up.
correct that... i can't vote because i changed my old vote and now it wont allow me...unless you edit the answer so i can.. if you want to let me know.
<shrug> Whatever. I looked at the other question - it does look like a bug, as another person posted. Good luck with it - I hate those types of bugs! :)
0

file:////MyNet/folder/image.jpg is not a file path. It's an URL.

1 Comment

ok let's say that i have this path "\\MyNet\folder\image.jpg" which points to a network folder. Can i open the file? and how?
0
    File f = new File("\\\\192.168.0.4\\mybookrw\\save\\command.txt");
    Desktop.getDesktop().open(f);

Worked fine for me. The one caveat is that you have to be authenticated against the share already. If you paste the path into the run box and it prompts you for a username and password then its not going to work from an app.

1 Comment

hm... my path is similar to this. it starts with \\\\ followed by the server name followed by the folder structure. And it doesn't work... Maybe because my path has spaces? does it work for you with spaces?
0

Everyone so far has assumed that the file isn't being found.

However, looking at the Desktop open() function, an IOException is thrown

if the specified file has no associated application or the associated application fails to be launched

Now, having said that, what happens if you open a jpg on your local machine? Also, what happens if you try manually launching the jpg through the network?

Edit: Actually, the problem may be that the default program set to open jpg files doesn't understand file:// uris. Sticking with UNC paths might be a better choice.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.