Sto provando in questo modo:
codice:
....
if (f.exists()) {
String msg = MessageFormat.format("The entry ''{0}'' already exists.\nDo you want to replace it?", new Object[]{f});
int r = JOptionPane.showConfirmDialog(null, msg, "Confirm", JOptionPane.YES_NO_OPTION);
if (r == JOptionPane.NO_OPTION) {
} else {
File workDir = new File(./work/);
File workFile = new File(workDir, f.getName());
try {
if (f.renameTo(workFile)) {
creaFilePdf.createPdf(tabellaMesi, tabellaTermocoppia, f, pathname, latitudine, longitudine, radiazioneAnnuale, inclinazioneOttimale, azimuth, menuCondizioni);
} else {
System.out.println("File già utilizzato");
}
} catch (DocumentException ex) {
Logger.getLogger(PVEstimation.class.getName()).log(Level.SEVERE, null, ex);
} catch (IOException ex) {
Logger.getLogger(PVEstimation.class.getName()).log(Level.SEVERE, null, ex);
}
}
...
però in questo modo mi visualizza il messaggio anche se il file esiste ma è chiuso (non solo se è aperto)
Come posso fare?
p.s. ho trovato questa soluzione parziale in una vecchia discussione: http://forum.html.it/forum/showthread/t-1543694.html