Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8340711
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T05:15:19+00:00 2026-06-09T05:15:19+00:00

I have the following method that is supposed to open the file that is

  • 0

I have the following method that is supposed to open the file that is passed in the associated program. It works for most files but if I pass any video or music file it prints java.io.IOException: Failed to open file:/C:/8GB/Bruno%20Mars%20-%20It%20will%20rain.mp3. Error message: Access is denied. (for example) and doesn’t open the file, even though it is associated with Windows Media Player!

private static void openFileinAssociate(File toOpen){
        // Open it using the operating system/environment
        Desktop environment = Desktop.getDesktop();
        if(toOpen.exists()){
            if(!toOpen.isDirectory())
                try{
                    environment.open(new File(toOpen.getAbsolutePath()));
                }catch(Exception ex){
                    ex.printStackTrace();
                    JOptionPane.showMessageDialog(null, "An error occured whilst trying to open the file.", applicationName, JOptionPane.ERROR_MESSAGE);
                }
        }
}

AND here is the rest of the stack trace as requested. I can really post anymore of the actual code though, sorry.

at sun.awt.windows.WDesktopPeer.ShellExecute(WDesktopPeer.java:77)
at sun.awt.windows.WDesktopPeer.open(WDesktopPeer.java:54)
at java.awt.Desktop.open(Desktop.java:272)
at main.GraphicUI.openFileinAssociate(GraphicUI.java:1930)
at main.GraphicUI.access$12(GraphicUI.java:1924)
at main.GraphicUI$17.mouseReleased(GraphicUI.java:837)
at java.awt.AWTEventMulticaster.mouseReleased(AWTEventMulticaster.java:290)
at java.awt.Component.processMouseEvent(Component.java:6505)
at javax.swing.JComponent.processMouseEvent(JComponent.java:3321)
at java.awt.Component.processEvent(Component.java:6270)
at java.awt.Container.processEvent(Container.java:2229)
at java.awt.Component.dispatchEventImpl(Component.java:4861)
at java.awt.Container.dispatchEventImpl(Container.java:2287)
at java.awt.Component.dispatchEvent(Component.java:4687)
at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4832)
at java.awt.LightweightDispatcher.processMouseEvent(Container.java:4492)
at java.awt.LightweightDispatcher.dispatchEvent(Container.java:4422)
at java.awt.Container.dispatchEventImpl(Container.java:2273)
at java.awt.Window.dispatchEventImpl(Window.java:2713)
at java.awt.Component.dispatchEvent(Component.java:4687)
at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:707)
at java.awt.EventQueue.access$000(EventQueue.java:101)
at java.awt.EventQueue$3.run(EventQueue.java:666)
at java.awt.EventQueue$3.run(EventQueue.java:664)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:76)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:87)
at java.awt.EventQueue$4.run(EventQueue.java:680)
at java.awt.EventQueue$4.run(EventQueue.java:678)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:76)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:677)
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:211)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:128)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:117)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:113)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:105)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:90)

I’m using Windows 7 and I have the latest version of Java…

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T05:15:20+00:00Added an answer on June 9, 2026 at 5:15 am

    The documentation of Desktop.open(File) states, that:

    Throws: IOException – if the specified file has no associated application or the associated application fails to be launched

    Try associating another application with the file in question and see if that works. Also, check the “Windows Event Log” to see if the WMP might be crashing when it’s opened.


    An alternative (which will work at least on Windows) is to use the Runtime.exec(String)-method and the start [file]-command to start the given file with it’s associated application.

    Runtime.exec("start \"C:\\Your\\Path with spaces\\file.whatever\"");
    

    Note: When your path has spaces in it, put the path in double quotes (need to be escaped in the String). Also, since the backslash is the escaping character for strings, it needs to be escaped, too.

    Also note that this method will open the “Choose appropriate application”-dialog, when there is no application assigned for the given file-type.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following method that is supposed to be a generic Save to
I have the following method that is replacing a pound sign from the file
I have a program that makes use of the following method to get a
I have the following method that is supposed to parse information from an XML
I have the following method that returns void and I need to use it
I have the following static method that prints the data imported from a 40.000
I have a method that contains the following (Java) code: doSomeThings(); doSomeOtherThings(); doSomeThings() creates
I have a method that I will use in the following contexts: 1. User
I have an interface (called Subject ) that has the following method: public void
I have a simple mapview that has the following viewdidload method and didupdate to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.