如何删除包含或不包含Java库INI4J的节?
这不起作用
Wini ini = new Wini(File);
System.out.println(Integer.toString(Position));
ini.remove(Integer.toString(Position));我也在ConfigParser上尝试过。
发布于 2012-03-11 18:20:42
你的代码什么也做不了,而且肯定不会编译。Wini不是正确的类,根据ini4j文档,您需要实例化Ini对象并使用Section对象删除/创建节。
我强烈建议您通读Ini4J文档。教程很棒,提供的示例回答了您的问题!
尽管你也可以继续阅读...
给定Ini文件
部分
某些键=某些值
somekey2 = somevalue2
somekey3 = somevalue3
(使用Ini4J)
我们可以写
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")));https://stackoverflow.com/questions/9651134
复制相似问题