Hi,

I am trying to open a url by clicking over the link of JLabel in Windows 7 (32 -bit) but unable to do so. After clicking on the link, it doesn't do anything. Although, it is opening the file successfully.It used to work in XP.

The code is as follows:

String osname = System.getProperties().getProperty("os.name").toUpperCase();                
if (osname.startsWith("WINDOWS")){
    Runtime.getRuntime().exec("rundll32 SHELL32.DLL,ShellExec_RunDLL \"" + path + "\"");                    
                       }
else{
    String[] commands = {"start", "\"\"", path};    
    Runtime.getRuntime().exec(commands);                                 
    }       

I would appreciate your help.

Recommended Answers

All 2 Replies

See if the browse() method of the Desktop class works for you.

        String[] cmd = new String[5];
        cmd[0] = "cmd.exe";
        cmd[1] = "/C";
        cmd[2] = "start";
        cmd[3] = "\"\"";
        cmd[4] = path;

        try {
            Runtime.getRuntime().exec(cmd);
        } 
        catch (IOException e) {
        }

The above code worked. Thanks anyway!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.