我的程序成功创建并填充了Excel(.xls)文件。一旦创建,我想在系统的默认程序中打开新文件(在我的情况下为Excel)。我怎样才能做到这一点?使用默认程序打开Excel文件
对于较旧的程序,我想用记事本打开一个txt文件,我用了以下内容:
if (!Desktop.isDesktopSupported()) {
System.err.println("Desktop not supported");
// use alternative (Runtime.exec)
return;
}
Desktop desktop = Desktop.getDesktop();
if (!desktop.isSupported(Desktop.Action.EDIT)) {
System.err.println("EDIT not supported");
// use alternative (Runtime.exec)
return;
}
try {
desktop.edit(new File(this.outputFilePath));
} catch (IOException ex) {
ex.printStackTrace();
}
当我尝试使用此代码为一个Excel文件,它给了我下面的错误:
java.io.IOException: Failed to edit file:C:/foo.xls
建议?
您可能会在这里找到类似的答案: –
jayaneetha
2016-04-11 08:51:18