java读取ini的配置文件

本文介绍了一款名为IniEditor的开源工具包,该工具用于轻松读取和编辑ini配置文件。通过示例代码展示了如何加载、修改并保存ini文件内容,包括添加注释和空白行等高级功能。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

由于项目需求,需要读取这种格式的ini配置文件

[group]
transfergroupname=BTM0
sysloghost=192.168.19.200

[business]
gateway=192.168.1.254
netmask=255.255.255.0

[gap]
netmask=255.255.255.0
[manage]
netmask=255.255.255.0

[remote]
gap=


在google上搜索了一遍,没有得到想要的结果。
后来发现了一个专门原来读取操作ini样式文件的开源工具包[url=http://www.ubique.ch/code/inieditor/]IniEditor[/url]

使用起来非常简单
Example code
Here's a minimal example. Suppose, we have this in a file called users.ini:


role = administrator
last_login = 2003-05-04

[joe]
role = author
last_login = 2003-05-13
Let's load that file, add something to it and save the changes:

IniEditor users = new IniEditor();
users.load("users.ini"); //加载
users.set("root", "last_login", "2003-05-16"); //编辑
users.addComment("root", "Must change password often");//添加注释
users.set("root", "change_pwd", "10 days");
users.addBlankLine("root");
users.save("users.ini"); //保存

This is how the file turned out:


role = administrator
last_login = 2003-05-16

# Must change password often
change_pwd = 10 days

[joe]
role = author
last_login = 2003-05-13
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值