Ho fatto così:
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 file = new File(f.getName());
FileChannel channel = new RandomAccessFile(file, "rw").getChannel();
// Get an exclusive lock on the whole file
FileLock lock = channel.lock();
try {
lock = channel.tryLock();
System.out.println("NON E' APERTO IN SCRITTURA");
} catch (OverlappingFileLockException e) {
System.out.println("E' APERTO ");
} finally {
lock.release();
}
}
} else {
creaFilePdf.createPdf(tabellaMesi, tabellaTermocoppia, f, pathname, latitudine, longitudine, radiazioneAnnuale, inclinazioneOttimale, azimuth, menuCondizioni);
}
In questo modo se il file non esiste me lo crea. Se invece il file esiste, sia che sia chiuso che aperto mi scrive il messaggio : "E' APERTO "
Non capisco!