java linux at_在ubuntu(linux)上从java打开一个带有Desktop.open()的路径

从我用

java编写的应用程序我想打开一个文件夹,使用操作系统文件资源管理器.

我使用Desktop.open(新文件(路径))

这在windows上工作正常,但在ubuntu 11.10(linux)上它不起作用.

使用Desktop.open打开文件确实可以在ubuntu和windows上运行.

使用介于两者之间的步骤:

文件fPath =新文件(fPath)

并使用fPath.exists()和fPath.isDirectory()测试它们都给出了true.

使用Desktop.open(新文件(路径))给我这个例外:

java.io.IOException: Failed to show URI:file:/and/here/the/path/I/use/

at sun.awt.X11.XDesktopPeer.launch(Unknown Source)

at sun.awt.X11.XDesktopPeer.open(Unknown Source)

at java.awt.Desktop.open(Unknown Source)

我还没能在苹果电脑上测试这个,但我希望Desktop.open(新文件(路径))是系统独立的……

顺便说一句,完整的代码:

Desktop desktop = null;

// Before more Desktop API is used, first check

// whether the API is supported by this particular

// virtual machine (VM) on this particular host.

if (!Desktop.isDesktopSupported()) {

// show Error

return;

}

desktop = Desktop.getDesktop();

String path = "here the path ";

// by the way: I use System.getProperty("file.separator") as file seperator

try {

File fPath=new File(path);

if(!fPath.exists()){

// show Error

return;

}

if(!fPath.isDirectory()){

// show Error

return;

}

desktop.open(new File(path));

} catch (IOException e) {

log.severe(e.getMessage());

e.printStackTrace();

// show Error

return;

}

一些额外的信息:

操作系统:Linux(3.0.0-16-通用 – amd64)

Java:1.6.0_30-b12

Java home:/opt/java/64/jre1.6.0_30

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值