Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Java - Desktop.getDesktop().browse(URI) is supported, but does not open document (a citrix problem?)

(I am not sure if this is the correct place to ask this question. Please move to suitable site)

I have a problem that is shown in below code. It does not work on machine (windows 2008) that has CITRIX Xen App 6-. There is no error, just that browser does not get launched. On my desktop (a windows7 box), it works.

package trials;

import java.awt.*;
import java.io.File;
import java.io.IOException;


public class Launch {

    public static void main(String[] args) throws IOException {
        if (args.length < 1) {
            System.out.println("argument filepath expected");
            return;
        }

        final boolean browseSupported = Desktop.getDesktop().isSupported(Desktop.Action.BROWSE);
        if ( !browseSupported) {
            System.out.println("Browse not supported");
            return;
        }

        final String filename = args[0];
        final File file = new File(filename);
        if (file.exists()) {
            Desktop.getDesktop().browse(file.toURI());
        } else {
            System.out.println(file.getAbsolutePath() + " does not exist");
        }
    }
}

I tried to use "open" as suggested in following answers. It did not work. The problem is narrowed down to 64bit version of Java(Oracle 1.6.0_25)

like image 786
Jayan Avatar asked Aug 26 '11 08:08

Jayan


2 Answers

To open a local file you have to use Desktop().open() not Desktop.browse()

like image 157
a_horse_with_no_name Avatar answered Sep 22 '22 12:09

a_horse_with_no_name


Another easy possibility that I have tested on Windows XP:

org.eclipse.swt.program.Program.launch("file://" + filename);
like image 41
Jakob Avatar answered Sep 19 '22 12:09

Jakob