Il mio programma crea e riempie correttamente un file Excel (.xls). Una volta creato, vorrei che il nuovo file si aprisse nel programma predefinito del sistema (Excel nel mio caso). Come posso raggiungere questo obiettivo?Apertura di un file Excel utilizzando il programma predefinito
Per un programma precedente dove volevo aprire un file txt in Blocco note, ho usato il seguente:
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();
}
Quando provo ad usare questo codice per un file Excel che mi dà il seguente errore:
java.io.IOException: Failed to edit file:C:/foo.xls
suggerimenti?
È possibile trovare la risposta simile qui: –
jayaneetha