我的程序可以成功地创建并填充Excel(.xls)文件。一旦创建完成,我希望能够在系统的默认程序中打开新文件(在我的情况下是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
建议?