Votre code ne fait rien et ne compile définitivement pas. Wini n'est pas la bonne classe, d'après les documents ini4j, vous devez instancier un objet Ini et supprimer/créer des sections en utilisant l'objet Section. Je recommande fortement de lire la documentation Ini4J. Les tutoriels sont super et les exemples fournis répondent à votre question!
Bien que vous pouvez continuer à lire aussi ...
Compte tenu du fichier ini
[Section]
somekey = somevalue
somekey2 = somevalue2
somekey3 = somevalue3
(à l'aide Ini4J)
Nous pouvons écrire
Ini iniFile = new Ini(new FileInputStream(new File("/path/to/the/ini/file.ini")));
/*
* Removes a key/value you pair from a section
*/
// Check to ensure the section exists
if (iniFile.containsKey("Section")) {
// Get the section, a section contains a Map<String,String> of all associated settings
Section s = iniFile.get("Section");
// Check for a given key<->value mapping
if (s.containsKey("somekey")) {
// remove said key<->value mapping
s.remove("somekey");
}
}
/*
* Removes an entire section
*/
if (iniFile.containsKey("Section")) {
// Gets the section and removes it from the file
iniFile.remove(iniFile.get("Section"));
}
// Store our changes back out into the file
iniFile.store(new FileOutputStream(new File("/path/to/the/ini/file.ini")));
Merci beaucoup. J'ai lu les JavaDocs. Je ne pouvais simplement pas le faire fonctionner pour enlever une section. Encore merci. – Verhelst