私のプログラムは、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
提案?