首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >INI4J -删除部分

INI4J -删除部分
EN

Stack Overflow用户
提问于 2012-03-11 07:32:32
回答 1查看 2.3K关注 0票数 0

如何删除包含或不包含Java库INI4J的节?

这不起作用

代码语言:javascript
复制
Wini ini = new Wini(File);
System.out.println(Integer.toString(Position));
ini.remove(Integer.toString(Position));

我也在ConfigParser上尝试过。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2012-03-11 18:20:42

你的代码什么也做不了,而且肯定不会编译。Wini不是正确的类,根据ini4j文档,您需要实例化Ini对象并使用Section对象删除/创建节。

我强烈建议您通读Ini4J文档。教程很棒,提供的示例回答了您的问题!

尽管你也可以继续阅读...

给定Ini文件

部分

某些键=某些值

somekey2 = somevalue2

somekey3 = somevalue3

(使用Ini4J)

我们可以写

代码语言:javascript
复制
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")));
票数 6
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/9651134

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档