Open a path with Desktop.open() from java on ubuntu (linux)

后端 未结 4 2134
星月不相逢
星月不相逢 2021-02-15 10:09

From my application written in java I want to open a folder, using the operating system file explorer.

I use Desktop.open(new File(path))

This works fine on wind

4条回答
  •  太阳男子
    2021-02-15 10:28

    I can't confirm the error. I took your code and constructed a main method around it, and everything works as expected. I don't exactly know where the default applications are set (in my case PCMan was opened instead of usual Nautilus, but it should fulfil its purpose in the end).

    Over at java.awt.Desktop.open doesn’t work with PDF files? I have found a link pointing to an issue in Suns (Oracles) bug tracker stating that the method for opening files using AWT isn't reliable even on Windows. Maybe you should think of alternative ways of opening such applications. Furthermore AWT is deprecating soon almost for sure.

    If you are utilizing SWT in your application, you could use org.eclipse.swt.program.Program.

提交回复
热议问题