Desktop.open() Problem

I recently put together an application that relied heavily on the Desktop.open( ) method and several other methods from the Desktop class. However, all of a sudden the Desktop.open() does not work. I believe I read some where that this was due to the ShellExecute function or dll or something like that.
However, since my app is targetted at the Windows platform I resorted to using windows Explorer to launch the system default applications for files using a the code below
public static void openFile(File file) {
  try {
    Runtime runtime = Runtime.getRuntime();
    runtime.exec( "explorer.exe \"" + file.getAbsolutePath() + "\"" );
  } catch(IOException) {
    ioe.printStackTrace();
    JOptionPane.showMessageDialog(null, "Could Not Open File Location: " + file.getAbsolutePath());
}The code works as expected, but my problem is that I am loosing cross-platform functionality.
Can any point my to solution to this Desktop.open( ) problem, or probably add the my list platform dependent launch procedures so at least the code works on Windows,Linux and Mac.
ICE

Thanks Andrew,
I've do a more simple example of the problem. I create two files on "\\fiuu\proyectosShared", one called "test.txt" and the other one called "te st.txt". I execute your exact source for the who paths whith these results:
File f = new File("//fiuu/proyectosShared/test.txt");
System.out.println(f + "  exists: " + f.exists());
dt.open(f);
RESULT:
\\fiuu\proyectosShared\test.txt  exists: true
(notepads opens the file)The second test does'nt work:
File f = new File("//fiuu/proyectosShared/te st.txt");
System.out.println(f + "  exists: " + f.exists());
dt.open(f);
RESULT:
\\fiuu\proyectosShared\te st.txt  exists: true
Exception in thread "main" java.io.IOException: Failed to open file:////fiuu/proyectosShared/te%20st.txt. Error message: El sistema no puede hallar la ruta especificada.
     at sun.awt.windows.WDesktopPeer.ShellExecute(WDesktopPeer.java:59)
     at sun.awt.windows.WDesktopPeer.open(WDesktopPeer.java:36)
     at java.awt.Desktop.open(Desktop.java:254)
     at DesktopTest.main(DesktopTest.java:14)
(translation of error message: System can't find specified path)I've also done some tests with Desktop.browse(file.toURI), and some others with no success.
Something curious: try to execute Runtime.getRuntime().exec("explorer " + f.getAbsolutePath) for a file that has thow white spaces on his name....
File f = new File("//fiuu/proyectosShared/te  st.txt");//with two white spaces
System.out.println(f + "  exists: " + f.exists());
Runtime.getRuntime().exec("explorer " + f.getAbsolutePath());
\\fiuu\proyectosShared\te  st.txt  exists: trueSystem says:
Explorador de Windows
La ruta '\\fiuu\proyectosShared\te st.txt' no existe o no es un directorio.
Aceptar  
(spanish version of File not found alert message)Note that in alert message one white space of filename is lost!
Thanks again
Edited by: pakomail on Nov 24, 2008 6:12 AM

Similar Messages

  • Desktop.open() problems

    I realise that this post might be quite similar to one posted yesterday, but I thought that the problem was sufficiently different to warrant a new thread.
    I'm trying to use the Desktop.open(file) method to open a file with the default application - so far I have gotten this to work successfully with Word files - however when I try to load a pdf file I get an error
    Failed to open file:/C:/Users/alex/Desktop/cup.pdf. Error message: No application is associated with the specified file for this operation.This seems strange since pdf file's are associated with Adobe Acrobat Reader on my computer. How does Java know which application to associate with the file type? I assume it's some native method, but if I call 'start c:/.../file.pdf' from the command line it opens the file with Acrobat Reader - So I'm stumped
    Any help would be greatly appreciated.
    Thanks

    I've just written a little test app to isolate the Desktop.open() call from our system :
    import java.awt.Desktop;
    import java.io.File;
    public class Test {
      public static void main(String[] arg) throws Exception {
        File file = new File(arg[0]);
        Desktop desktop = Desktop.getDesktop();
        desktop.open(file);
    }Running this as
    java Test C:\Users\alex\Desktop\cup.pdfGives me the error
    Exception in thread "main" java.io.IOException: Failed to open file:/C:/Users/alex/Desktop/cup.pdf.
    Error message: No application is associated with the specified file for this operation.
            at sun.awt.windows.WDesktopPeer.ShellExecute(Unknown Source)
            at sun.awt.windows.WDesktopPeer.open(Unknown Source)
            at java.awt.Desktop.open(Unknown Source)
            at Test.main(Test.java:10)

  • Desktop class problem

    The code below does nothing. No file opened, no exception thrown, no output.
    What can I do to discover the problem?
    It does indeed execute the desktop.open(file) line.
    Using JDK 1.16.0_81
    File file = new File(pathAndFileString); // an existing text file
    if (Desktop.isDesktopSupported()) {
         Desktop desktop = Desktop.getDesktop();
         if (desktop.isSupported(Desktop.Action.OPEN )) {
              try {
                   desktop.open(file);
              } catch (IOException e1) {
                   e1.printStackTrace();
         else {
              System.out.println("Desktop.Action.OPEN not supported");
    else {
         System.out.println("Desktop not supported");
    }

    package desktopdemo;
    import java.awt.Desktop;
    import java.io.File;
    import java.io.IOException;
    public class MyDesktopDemo {
         public MyDesktopDemo() {
              // have tried .txt, .rtf, .pptx all with no effect
              String pathAndFileString = "C:\\my.pptx";
              File file = new File(pathAndFileString);
              if (Desktop.isDesktopSupported()) {
                   Desktop desktop = Desktop.getDesktop();
                   if (desktop.isSupported(Desktop.Action.OPEN )) {
                        try {
                             System.out.println("desktop.open(" + pathAndFileString + ")"); // gets here
                             desktop.open(file); // but nothing happens
                        } catch (IOException e1) {
                             e1.printStackTrace();
                   else {
                        System.out.println("Desktop.Action.OPEN not supported");
              else {
                   System.out.println("Desktop not supported");
        public static void main(String args[]) {
            java.awt.EventQueue.invokeLater(new Runnable() {
                public void run() {
                    new MyDesktopDemo();
    }

  • Desktop.open() method doesn't work,

    Hi,
    I'm developing file explorer with JDK6.
    But when I try to open file with native asscociation programs with java.awt.Desktop class, I found that's not work at all.
    there is no response, exception and error. it just 'silent.'
    I checked each line of code. File is exist, Desktop support Open action.
    OS association with file is correct. I couldn't find any problem.
    so I tested tutorial code 'DesktopDemo'. it worked well Browse() but not Open(). open() method isn't work. (It also silent)
    How can I open file with native association?

    Please don't post to threads which are long dead, and don't hijack another poster's thread. When you have a question, start your own thread. Feel free to post a link to a related thread.
    Discussions may be kept on the forum. This is not a place to advertise your blog.
    I'm locking this thread now.
    db
    StijnDeWitt wrote:
    This seems to be a long-running problem related to Desktop.open in combination with Windows and some Account/Profile settings on Windows which are as of yet undetermined.
    Unfortunately the moderators of this forum have the tendency to close/lock old topics so we cannot add new information to a long running problem anymore after a while. They forgot to close this one so luckily I can still add some info here.
    I would like to invite anyone wanting to read details on and discuss this issue to do so on my blog. The comments on that post will never be closed or locked.
    java.awt.Desktop open() fails silently without exception
    (blog link removed)
    >
    You may also want to have a look at these related (but unfortunately locked) forum posts:
    [Desktop.open fails without exception, nothing happens (Locked)|http://forums.sun.com/thread.jspa?threadID=5338022]
    [Desktop.getInstance().open(file) does nothing (nothing happens) (Locked)|http://forums.sun.com/thread.jspa?threadID=5413798]

  • Desktop.open() fails when file contains German umlauts

    Hello,
    I want to open a file using the Desktop-API:
    // check whether opening a file is supported or not
    if (!desk.isSupported(Desktop.Action.OPEN)) {
      // display error message box
      JOptionPane.showMessageDialog(getFrame(),getResourceMap().getString("errLinkUnsopportedMsg"),
             getResourceMap().getString("errLinkUnsopportedTitle"),JOptionPane.ERROR_MESSAGE);
      return;
    desk.open(linkfile);I'm catching all possible exceptions here:
                 catch (IOException e)
                catch (IllegalArgumentException e)
                catch (SecurityException e)
                catch (UnsupportedOperationException e)
                catch (URISyntaxException e)But when I want to open a file that contains German umlauts, my application throws following exception:
    Exception in thread "AWT-EventQueue-0" java.lang.RuntimeException:
    Non-Java exception raised, not handled!
    (Original problem: *** -[NSCFArray initWithObjects:count:]:
    attempt to insert nil object at objects[0])
    at apple.awt.CDesktopPeer._lsOpen(Native Method)
    at apple.awt.CDesktopPeer.lsOpen(CDesktopPeer.java:53)
    at apple.awt.CDesktopPeer.open(CDesktopPeer.java:33)
    at java.awt.Desktop.open(Desktop.java:254)
    at zettelkasten.ZettelkastenView.eventHyperlinkActivated(ZettelkastenView.java:9609)
    at zettelkasten.ZettelkastenView.access$6000(ZettelkastenView.java:119)
    at zettelkasten.ZettelkastenView$14.hyperlinkUpdate(ZettelkastenView.java:7014)The file does definitely exist. I chose it with a filechooser, and I debugged the source step-by-step. Before calling the desktop.open() command, I check whether the file exists or not (File.Exists()).
    When I open any file without umlauts, everything is fine. Only files with umlauts in their filename seem to make trouble.
    My OS is:
    Mac OS X 10.5.5, running the latest Java 6, using NetBeans 6.5
    Is there any solution, or at least a workaround?
    Thanks in advance!
    Daniel
    Edited by: DnlLdck on Jan 29, 2009 6:23 AM

    Same thing happened to me, but I was trying to browse an URI which contains non-English characters. Haven't try it on Windows yet. Maybe it does not support non-English characters on Mac.

  • Java 6 Desktop open

    I want to be able to open files with the default application from java. The Desktop class works for this when using:
    1. local filepaths
    2. network drives
    3. UNC pathnames
    but does not when the UNC pathnames have spaces in them!
    Does anyone know how to solve this problem?

    Hi,
    I also have the same problem, but with my JNI and C++ expertise, I was able to isolate the problem.
    My platform:
    - Microsoft Windows XP, Family Edition (French), Version 2002, Service Pack 3
    - JRE 1.6.0_21
    In the source of the JDK6 (Src/windows/classes/sun/awt/windows/WDesktopPeer.java), the Desktop.open(file) calls the native method
    ShellExecute(*uri.toString()*, "open")
    For example, if you try to open "c:\helloworld.pdf",
    uri.toString() = "*file:/c:/helloworld.pdf*"if I call ShellExecute("C:\\helloworld.pdf", "open"), it works
    but if I call ShellExecute(" file:/c:/helloworld.pdf", "open"), it doesn't work on my platform.
    In both case, the ShellExecuteW or ShellExecuteA function of the Windows API return the integer 42 (> 32), saying that the functions succeeded. If the file object is not correct, the function should return a value <= 32.
    => The bug is not due to Java implementation, but to a bug in the Windows API.
    Other remark:
    I also tried the "ShellExec_RunDLL" entry point of the Shell32.dll library using RunDll32 utility. Both commands below are running correctly:
    rundll32 SHELL32.DLL,ShellExec_RunDLL "C:\hello.pdf"
    rundll32 SHELL32.DLL,ShellExec_RunDLL "file:/C:/hello.pdf"My conclusion:
    1) A workaround could be implemented in the JRE: use the file path without the "file:/" protocol prefix.
    2) This bug seems to be present only one some version of Windows XP (to confirm).
    Rodolphe.

  • I was clsoing Word and suddenly everything on my desktop opened - I had to close each one and then a page requesting guest access to Cisco appeared. I cannot access any of my websites or bookmarks now. What do I do - or what did I do?

    I was closing Word, was on my desktop page when suddenly all my windows on the desktop opened at once. I had to close each one and then a page requesting guest access to Cisco appeared. It required a password ( ? ) which I do not have. Now I cannot access any of my webpages or bookmarks, including mail etc. I have no idea what I might have done to cause this problem. I am not particularly savvy and don't know where to begin.

    daveynielsen wrote:
    So my question is... if you took the time to read this.. why in the world did everything stop working with wi fi and out of nowhere asked me to use a blackberry data service plan?
    Because, without THE BlackBerry Data Plan, you will only have use of your WiFi HotSpot browser, and that is that. No email, none of the RIM data application features like AppWorld or the BlackBerry Facebook application.
    It worked at first, because you probably had leftover provisioning Service Books from the previous owner, I am guessing (you mentioned "checked with my seller).
    To me, seems be working as suspected.
    daveynielsen wrote:
    Well, naturally i figured everything else would work on a wif connection.. like the iphone. Even though you dont have the 3G data plan one can still access email, web, and aps.
    Not quite, you must still have a data plan for the iPhone.
    1. If any post helps you please click the below the post(s) that helped you.
    2. Please resolve your thread by marking the post "Solution?" which solved it for you!
    3. Install free BlackBerry Protect today for backups of contacts and data.
    4. Guide to Unlocking your BlackBerry & Unlock Codes
    Join our BBM Channels (Beta)
    BlackBerry Support Forums Channel
    PIN: C0001B7B4   Display/Scan Bar Code
    Knowledge Base Updates
    PIN: C0005A9AA   Display/Scan Bar Code

  • OS X and Desktop.open()

    I use the following code to open an image with the default image viewer on Mac OS X.
    Runtime.getRuntime().exec(new String[]{"/usr/bin/open", data.directory + File.separatorChar + data.name});
    It works fine in development but as soon as I run it in a signed web start application, it only works if "Preview" (the default image app) is already open. No exceptions are thrown when it doesn't work.
    Interestingly, I have a "Show In Finder" option that uses a variation of the same command:
    Runtime.getRuntime().exec(new String[]{"/usr/bin/open", "-R", data.directory + File.separatorChar + data.name});
    It works every time regardless of whether I'm running in web start or not.
    I also tried using Desktop.open() and it behaves exactly the same way. This is on Mac OS X mountain lion with JDK 1.7u13.

    Back up all data.
    Triple-click the line of text below to select it, the copy the selected text to the Clipboard (command-C):
    /Library/Internet Plug-ins
    In the Finder, select
    Go ▹ Go to Folder
    from the menu bar, or press the key combination shift-command-G. Paste into the text box that opens (command-V), then press return.
    From the folder that opens, remove any items that have the letters “PDF” in the name. You may be prompted for your login password. Then quit and relaunch Safari, and test.
    The "Silverlight" web plugin distributed by Microsoft can also interfere with PDF display in Safari, so you may need to remove it as well, if it's present.
    If you still have the issue, repeat with this line:
    ~/Library/Internet Plug-ins
    If you don’t like the results of this procedure, restore the items from the backup you made before you started. Relaunch Safari again.

  • Image open problem in nokia 5230

    Dear All,
    I have nokia 5230 mobile & i am using from last 10 months but from past few days i am facing problem regarding image/songs open problem.  whenever i trying to open image my phone gets hang & it shows nothing in it but i have 100 pics in memory card, same problem is with songs whenever i put some songs in memry card but songs gallery after refreshing shows nothing.
    Please help me to resolve this issue.
    Vipul

    im not sure what to do about the images but the same happened with the songs. here is waht i did:
    1. make sure you have the latest firmware installed (fw. 50).
    2. when it is installed copy all tracks to pc and install nokia ovi music.
    3. delete the folder called 'music' on your memory card.
    4. open ovi music and add songs to playlists and copy to device. this will create a new folfre called 'music' and the error should be fixed
    if that fails you should try a program called lcg jukebox as this is a much better music player 

  • Oracle error - Open problem

    hi friends,
    on accessing the database i get this following error:
    Open Problem - ORA-01034: ORACLE not available ORA-27101: shared memory realm does not exist Execution Problemnull
    How can i resove it...

    Here's a wild idea.... check the Oracle site/documentation for suggestions ?

  • Calling Desktop.open() on avi/mp3/wmv/etc (media) files.

    Hello all,
    I am using the Desktop class to open files on the desktop in my signed applet. This is working perfectly for ppt, pps, doc, xls, txt, jpg, pdf files. However, for some reason I am unable to launch any media-type files using this method. I get errors such as "java.io.IOException: Failed to open file:/C:/Users/Bryan/Desktop/4542-sun/Butterfly.wmv. Error message: No application is associated with the specified file for this operation."
    However, there are indeed applications associated with these file types... namely Windows Media Player. Double-Clicking the file directly launches it in WMP as it should. I have been searching around high and low, and can't find much. Note the fact that it is trying to open a URI, starting with file:/. Originally it was just opening the location directly, but I tried using a URI instead to no avail.
    This has happened on 3 separate computers now.
    I have done a work around using Runtime.getRuntime().exec(). However, some of the filenames I am working with can possibly have asian and other UTF-8 characters. That causes a whole new issue, described in http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4947220. I have no idea how to begin using JNI to directly call ShellExecute or if that is even possible from a signed applet standpoint.
    Does anyone have any idea how to fix the issue with Desktop.open() and media files?
    Thanks

    Ok I have searched and searched and found no reliable solution for either of the previous issues. Since this applet is run on a closed intranet, with no fear of malicious intent, I have gone for a different route.
    try {
         desktop.open(new File(fileToOpen.toURI()));
    } catch (Exception e) {
         window.call("launchFile", new Object[] { file.toString() });
    }When the call to Desktop.open() fails, I catch the exception and call a javascript function launchFile(), defined below.
    function launchFile(filename) {
            var o = new ActiveXObject("WScript.Shell");
            o.run(filename);
    }Of course, this limits us to IE ... but it is a necessary evil until Sun fixes the bugs in Desktop.open() and Runtime.exec().
    Hope this helps someone. Again, I still welcome other options.

  • Post Moved BT Broadband Desktop help problem

    Post Moved to Other BB Queries http://community.bt.com/t5/Other-BB-Queries/BT-Broadband-Desktop-Help-problem/td-p/46973
    If you want to say thanks for a helpful answer,please click on the Ratings star on the left-hand side If the reply answers your question then please mark as ’Mark as Accepted Solution’

    Hi FrankC
    I am sorry this still a problem.
    If you could drop me an email please with your BT account and telephone number along with a link back to this thread I'll get this sorted out for you.
    Just send to the address in my profile. 
    With regards to the thread being marked as solved as the original poster you can unmark the thread as solved.  Just select 'Options' at the top right of the post.  KerryG has posted up a pretty useful guide on this here. 
    Cheers
    Craig
    BTCare Community Mod
    If we have asked you to email us with your details, please make sure you are logged in to the forum, otherwise you will not be able to see our ‘Contact Us’ link within our profiles.
    We are sorry but we are unable to deal with service/account queries via the private message(PM) function so please don't PM your account info, we need to deal with this via our email account :-)”
    td-p/30">Ratings star on the left-hand side of the post.
    If someone answers your question correctly please let other members know by clicking on ’Mark as Accepted Solution’.

  • I have different desktops open on my mac, but when I try to go to a different desktop, my mac automatically goes back to the main desktop

    I have different desktops open on my mac, but when I try to go to a different desktop, my mac automatically goes back to the main desktop

    Unfortunately, when I open applications, adobe photoshop elements 13 folder does not appear in the adobe folder. It appears as a disk on the desktop, only.

  • Why are the videos sent from my daughter's iPhone 4 to my 4S in 3gp format? i need to drag to desktop - open with QuickTime - convert - reimport into iPhoto.

    why are the videos sent from my daughter's iPhone 4 to my 4S in 3gp format? i need to drag to desktop - open with QuickTime - convert - reimport into iPhoto. There must be another way.  Plus

    Hey joshuafromisr,
    If you resintall iTunes, it should fix the issue. The following document will go over how to remove iTunes fully and then reinstall. Depending on what version of Windows you're running you'll either follow the directions here:
    Removing and Reinstalling iTunes, QuickTime, and other software components for Windows XP
    http://support.apple.com/kb/HT1925
    or here:
    Removing and reinstalling iTunes, QuickTime, and other software components for Windows Vista or Windows 7
    http://support.apple.com/kb/HT1923
    Best,
    David

  • Emachine desktop- audio problems while World of Warcraft is open

    I play the above video game on my new emachine desktop that I got for Christmas and when I first installed it there weren't any problems. For a few months now I've been having trouble having audio while World of Warcraft is open. It even happens with in-game sound. The speakers will make this staticy sound that sometimes sounds like a disc skipping. I know it isn't my speakers because they work fine when WoW is closed.
    In-game support told me that my RAM isn't big enough to support audio and the game.
    Geek Squad said that my drivers needed to be updated.
    A friend told me to change my auto settings in-game because I might have it set to too many sound channels.
    Well, I checked every driver and they're all up to date. I don't know much about comps except the basics, so I'm not sure what to do if it really is the RAM. The advice my friend gave me worked for like 5 minutes and then went back to the same thing.
    I have no idea what it is or how to fix it, so I was hoping that someone on here might help.
    Thanks.

    Well, how about I just put all the info that's written on the side here lol.
    AMD Athlon 2650e Processor
    NVIDIA GeForce 8200 Graphics
    3200GB Hard Drive
    2GB DDR2 Memory
    Windows Vista
    emachines EL1210-01e
    notsotecy = not so techy 
    I went to my control panel and updated my drivers like Geek Squad said to. This program called Driver Detective tolf me which it thought needed to be updated (half that it said needed to really didn't need to...so I deleted it.).
    The game manual for the latest expansion says 1GB needed for Vista users but it's recommended to have 2GB for Vista users.
    The expansion before that says 1 GB of RAM is recommended
    Then the original version says...ok, I have no idea since I can't find the manual.
    Lastly, would the mothe board driver be with the rest? If so, then I already updated it.

Maybe you are looking for