0

i already tried with this.

    String userHomePath = "\\mysvr\\project\\my Team\\001 test\\001 test\\003 Report";
    File userHome = new File(userHomePath);
    try {
        Desktop.getDesktop().open(userHome);
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

Why it can't open? Plz explain me. Because of white spaces? if so, how can i fix it. Thanks

Here's exception:

java.io.IOException: Failed to open file:////mysvr/project/my%20Team/001%20test/001%20test/003%20Report/. Error message: The system cannot find the file specified.
    at sun.awt.windows.WDesktopPeer.ShellExecute(Unknown Source)
    at sun.awt.windows.WDesktopPeer.open(Unknown Source)
    at java.awt.Desktop.open(Unknown Source)
    at org.ace.insurance.fire.renewal.Test.main(Test.java:13)

i can open till "\mysvr\project" .

9
  • 4
    Have you tried \\\\mysvr\\project\\? Commented Jun 27, 2014 at 11:18
  • Please post the stack trace or a description of the problem other than that it won't open. Commented Jun 27, 2014 at 11:19
  • 1
    No, just four backslashes for the first one - \\\\mysvr\\project\\my Team etc. Commented Jun 27, 2014 at 11:20
  • This is odd -- the error message indicates that something did a URL encoding on the filename, and I didn't think new File() would do that. Commented Jun 27, 2014 at 11:27
  • 1
    Personally, what I'd do instead of guessing at the right way to specify the location is throw together a little Swing app and using JFileChooser, navigate to and select the location. In other words, let Java tell you what it thinks the path to the location is. Commented Jun 27, 2014 at 11:33

4 Answers 4

1

Use "//mysvr/project/..." or "\\\\mysvr\\project\\...".

Of course first try it out in a Windows Explorer. Doubling any backslash in a Java String literal.

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

1 Comment

Split the problem in parts: try String files = userHome.list();. And then try Desktop.getDesktop().browse(userHome.toURL());. However I saw now stackoverflow.com/questions/7201722/…
0

Try this:

   String userHomePath = "\\\\mysvr\\project\\my Team\\001 test\\001 test\\003 Report";
File userHome = new File(userHomePath);
try {
    Desktop.getDesktop().open(userHome);
} catch (IOException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
}

1 Comment

Are you sure you can reach the server from Windows Explorer?
0

Include quotes as part of the path:

String userHomePath = "\"\\mysvr\\project\\my Team\\001 test\\001 test\\003 Report\"";

Comments

0

With the addition of //mysvr/project/... or \\\\mysvr\\project\\... as @Joop Eggen (and other already) mentioned your code works on me also.

Without the double forward slash it don't. So either check the availability of the folder in explorer and if it is available (or exist etc).

If both conditions are met then I don't know what else to suggest.

P.S. The exception thrown for both cases is the same: java.lang.IllegalArgumentException

2 Comments

Curious: did you try with spaces in the path? I have that itching idea that the spaces is what makes and breaks it for the OP.
Well then, that makes the answer easy: the OS is not lying and the path -really- does not exist :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.