论坛首页 入门技术论坛

java读取ini的配置文件

浏览 2185 次
精华帖 (0) :: 良好帖 (0) :: 新手帖 (0) :: 隐藏帖 (0)
作者 正文
   发表时间:2009-10-20   最后修改:2009-10-20
由于项目需求,需要读取这种格式的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样式文件的开源工具包IniEditor

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

   [root]
   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:

   [root]
   role = administrator
   last_login = 2003-05-16

   # Must change password often
   change_pwd = 10 days

   [joe]
   role = author
   last_login = 2003-05-13


论坛首页 入门技术版

跳转论坛:
Global site tag (gtag.js) - Google Analytics