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" .

Pyae Phyo Aung
  • 161
  • 1
  • 1
  • 10
  • 4
    Have you tried \\\\mysvr\\project\\? – reto Jun 27 '14 at 11:18
  • Please post the stack trace or a description of the problem other than that it won't open. – Paul Jun 27 '14 at 11:19
  • 1
    No, just four backslashes for the first one - `\\\\mysvr\\project\\my Team` etc. – Dawood ibn Kareem Jun 27 '14 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. – arcy Jun 27 '14 at 11:27
  • Can you open that path using the underlying OS? Java says it can't find the file - are you sure you have it correct in the code? – Paul Jun 27 '14 at 11:27
  • i can open that path using the underlying OS. @Paul – Pyae Phyo Aung Jun 27 '14 at 11:30
  • 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. – Paul Jun 27 '14 at 11:33
  • @Paul, i dun want to use JFileChooser, plz tell me a way to open the path , Thanks. – Pyae Phyo Aung Jun 27 '14 at 11:37
  • I provided an answer below. I was not suggesting you use JFileChooser as part of your application, just that you use it to troubleshoot the problem. – Paul Jun 27 '14 at 11:39

4 Answers4

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.

Joop Eggen
  • 107,315
  • 7
  • 83
  • 138
  • Split the problem in parts: try `String files = userHome.list();`. And then try `Desktop.getDesktop().browse(userHome.toURL());`. However I saw now http://stackoverflow.com/questions/7201722/java-desktop-getdesktop-browseuri-is-supported-but-does-not-open-document – Joop Eggen Jun 27 '14 at 11:47
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();
}
Tarik
  • 10,810
  • 2
  • 26
  • 40
0

Include quotes as part of the path:

String userHomePath = "\"\\mysvr\\project\\my Team\\001 test\\001 test\\003 Report\"";
Paul
  • 19,704
  • 14
  • 78
  • 96
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

Eypros
  • 5,370
  • 6
  • 42
  • 75
  • 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. – Gimby Jun 27 '14 at 13:09
  • Well then, that makes the answer easy: the OS is not lying and the path -really- does not exist :) – Gimby Jun 27 '14 at 13:27