Results 1 to 12 of 12
Like Tree1Likes
  • 1 Post By wsaryada

Thread: Can't open shared server folder with spaces in name?

  1. #1
    IYIaster is offline Member
    Join Date
    Jul 2009
    Posts
    46
    Rep Power
    0

    Default Can't open shared server folder with spaces in name?

    Java Code:
            File foler = new File("\\\\server01\\New Folder");
            System.out.println(foler);
            Desktop desktop = null;
            if (Desktop.isDesktopSupported()) {
                desktop = Desktop.getDesktop();
            }
    
            try {
                desktop.open(foler);
            } catch (IOException e) {
            }
    I also tried

    Java Code:
            File foler = new File("\"" + "\\\\server01\\New Folder" + "\"");
            System.out.println(foler);
            Desktop desktop = null;
            if (Desktop.isDesktopSupported()) {
                desktop = Desktop.getDesktop();
            }
    
            try {
                desktop.open(foler);
            } catch (IOException e) {
            }
    If there are not any spaces in the file name it works fine.

    Thanks for your time!

  2. #2
    jim829 is offline Senior Member
    Join Date
    Jan 2013
    Location
    United States
    Posts
    3,340
    Rep Power
    5

    Default Re: Can't open shared server folder with spaces in name?

    The first version works fine for me. Can you please paste the exact error you are getting.

    Regards,
    Jim
    The Java™ Tutorial | SSCCE | Java Naming Conventions
    Poor planning our your part does not constitute an emergency on my part.

  3. #3
    IYIaster is offline Member
    Join Date
    Jul 2009
    Posts
    46
    Rep Power
    0

    Default Re: Can't open shared server folder with spaces in name?

    That's the thing, I'm not getting any error it just doesn't open a window.

    Setting the path as "\\\\server01\\NewFolder" opens the window fine.

    My OS is Windows 7 Professional x64 if that helps.

  4. #4
    jim829 is offline Senior Member
    Join Date
    Jan 2013
    Location
    United States
    Posts
    3,340
    Rep Power
    5

    Default Re: Can't open shared server folder with spaces in name?

    My mistake. I was looking for an error of some sort. I'll check it out.

    Regards,
    Jim
    The Java™ Tutorial | SSCCE | Java Naming Conventions
    Poor planning our your part does not constitute an emergency on my part.

  5. #5
    jim829 is offline Senior Member
    Join Date
    Jan 2013
    Location
    United States
    Posts
    3,340
    Rep Power
    5

    Default Re: Can't open shared server folder with spaces in name?

    Putting an e.printStackTrace() in your catch routine explains what is happening. Don't have a solution yet though.

    Regards,
    Jim
    The Java™ Tutorial | SSCCE | Java Naming Conventions
    Poor planning our your part does not constitute an emergency on my part.

  6. #6
    jim829 is offline Senior Member
    Join Date
    Jan 2013
    Location
    United States
    Posts
    3,340
    Rep Power
    5

    Default Re: Can't open shared server folder with spaces in name?

    Apparently its a bug and has been around for some time. Here is the link.

    Bug ID: 6780505 java.awt.Desktop.getDesktop().open() fails on shared files with white spaces

    An alternative is to use JFileChooser. You can set the Look and Feel to the system to get the effect of the current platform.

    Regards,
    Jim
    The Java™ Tutorial | SSCCE | Java Naming Conventions
    Poor planning our your part does not constitute an emergency on my part.

  7. #7
    IYIaster is offline Member
    Join Date
    Jul 2009
    Posts
    46
    Rep Power
    0

    Default Re: Can't open shared server folder with spaces in name?

    So, this bug has been known for 2 1/2 years and sun hasn't fixed it. That sounds like them. Thanks for your help. If you are able to find a work around please let me know.

  8. #8
    IYIaster is offline Member
    Join Date
    Jul 2009
    Posts
    46
    Rep Power
    0

    Default Re: Can't open shared server folder with spaces in name?

    Doing it this way seems to work.

    Java Code:
    try {
        String command = "cmd /c %windir%\\explorer.exe \\\\server01\\New Folder";
        Runtime.getRuntime().exec(command);
    
    } catch (IOException e) {
    }
    Fortunately the program will only be used in Windows.
    Last edited by IYIaster; 03-05-2013 at 09:20 PM.

  9. #9
    wsaryada is offline Senior Member
    Join Date
    Jun 2007
    Location
    Bali, Indonesia
    Posts
    758
    Rep Power
    8

    Default Re: Can't open shared server folder with spaces in name?

    You might also try something like the following (JDK 7 required).

    Java Code:
    Path path = Paths.get("\\\\server01\\New Folder");
    try {
        desktop.browse(path.toUri());
    } catch (IOException e) {
        e.printStackTrace();
    }
    jim829 likes this.

  10. #10
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,188
    Rep Power
    19

    Default Re: Can't open shared server folder with spaces in name?

    Quote Originally Posted by IYIaster View Post
    So, this bug has been known for 2 1/2 years and sun hasn't fixed it. That sounds like them.
    Sun?

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  11. #11
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,755
    Rep Power
    19

    Default Re: Can't open shared server folder with spaces in name?

    Quote Originally Posted by wsaryada View Post
    You might also try something like the following (JDK 7 required).

    Java Code:
    Path path = Paths.get("\\\\server01\\New Folder");
    try {
        desktop.browse(path.toUri());
    } catch (IOException e) {
        e.printStackTrace();
    }
    Nice (it works).
    And I suspect this is why they never bothered to fix it.
    And I doubt it ever will be now as 6 is no longer supported.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  12. #12
    jim829 is offline Senior Member
    Join Date
    Jan 2013
    Location
    United States
    Posts
    3,340
    Rep Power
    5

    Default Re: Can't open shared server folder with spaces in name?

    After reviewing your example and doing some research I also discovered that this will work (but your way is more friendly). This works in at least JDK 1.6.

    Java Code:
         try {
             URI uri = new URI("file://server01/New%20Folder");
             Desktop desktop = Desktop.getDesktop();
              desktop.browse(uri);
          } catch (Exception e) {
              e.printStackTrace();
          }
    One could easily write a method to format a path to a URI (which is what Path.toUri does). But upgrading to JDK 1.7 is the way to go. Especially since there are lots of new features.

    Regards,
    Jim
    The Java™ Tutorial | SSCCE | Java Naming Conventions
    Poor planning our your part does not constitute an emergency on my part.

Similar Threads

  1. Listing the shared folder on a remote computer
    By c4rb0n in forum Networking
    Replies: 3
    Last Post: 02-06-2012, 12:49 PM
  2. Archiving File on Shared Folder in Linux using java code
    By ajmerasunny in forum Advanced Java
    Replies: 1
    Last Post: 10-30-2009, 07:15 AM
  3. Folder Creation On Shared Hosting Account
    By arpitgadle in forum Java Servlet
    Replies: 2
    Last Post: 10-03-2009, 02:04 PM
  4. Access Linux shared folder from Windows OS
    By nitinpjairaj in forum Networking
    Replies: 3
    Last Post: 08-26-2008, 06:14 PM
  5. how to access shared file/folder in LAN
    By ksheetiz in forum Networking
    Replies: 1
    Last Post: 05-24-2008, 04:54 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •