从我用java编写的应用程序我想打开一个文件夹,使用操作系统文件资源管理器.
我使用Desktop.open(新文件(路径))
这在windows上工作正常,但在ubuntu 11.10(linux)上它不起作用.使用Desktop.open打开文件确实可以在ubuntu和windows上运行.
使用介于两者之间的步骤:文件fPath = new File(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)
Run Code Online (Sandbox Code Playgroud)
我还没能在苹果电脑上测试这个,但我希望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") …Run Code Online (Sandbox Code Playgroud) 我有Windows XP和开发一些Java swing应用程序.
在我正在使用的程序中
Runtime.getRuntime().exec("rundll32 SHELL32.DLL,ShellExec_RunDLL "+ myfile);
在Windows默认编辑器中打开我的程序生成的文件.
它在我的系统上工作正常.我只是想知道它在Windows 7上
是否正常工作.在Windows 7 中这个流程执行是否有任何安全方面没有出现在Windows XP中?
我想知道Java中的代码,这将有助于执行与文件上的任何操作系统中的双击相同的操作,使其打开,从而使我们能够在用户提供其位置时查看其内容.在他/她的电脑中存档.任何建议都会有很大的帮助,因为我需要它来完成我的申请.