File f = new File(fullName);
// Mi assicuro che il file non esista gia'
if (f.exists())
throw new CannotWriteFileException(cName, "File already exists");
// Ora creo le cartelle intermedie (se necessario)
if (!new File(fullName.substring(0, fullName.lastIndexOf(File.separator))).mkdirs())
throw new CannotWriteFileException(cName, "Cannot create intermediate directories");
// Mi assicuro di poter scrivere sul file
try {
if (!f.createNewFile() || !f.canWrite())
throw new CannotWriteFileException(cName, "Unable to write to file (probably read-only)");
} catch (IOException e) {
throw new CannotWriteFileException(cName, e.getCause() + " - " + e.getLocalizedMessage());
}
ConfigurationParser.save(xmlDocument, fullName);
}