如何从Java中的.ini文件读取子组值? [英] How to read sub group values from .ini file in java?

查看:251
本文介绍了如何从Java中的.ini文件读取子组值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的.ini文件具有以下结构:

i have .ini file with following structure:

    [HEADING1][SUBHEADING]
    DBUSer=John
    DBPASSWD=Joe1234

我无法从组(HEADING1)的子组(SUBHEADING)中读取值.我尝试不搜索净值但找不到任何提示,请分享您的看法.

i am not able to read values from the subgroup(SUBHEADING) of group (HEADING1).I tried hard to search not net but not find any hint, please share your view on that.

我能够读取具有以下结构的.ini文件:

i am able to read .ini file with this structure:

    [HEADING1]
    DBUSer=John
    DBPASSWD=Joe1234

但是对于亚组,我面临问题.

but for subgroup i am facing problem.

   Ini ini = new Ini(new File("/path/to/file"));
   System.out.println(ini.get("HEADING1", "DBUSer"));

或者如果您有任何其他解决方案或库,请在此处共享.

or if you have any other solution or library please share it here.

推荐答案

我还没有尝试过,但是根据文档,使用TreeModel应该可以做到这一点:

I haven't tried this, but according to the documentation this should be possible by using the TreeModel:

Ini ini = new Ini(new File("/path/to/file"));
System.out.println(ini.get("HEADING1/SUBHEADING", "DBUSer"));

您可以在此处(方法sample05()).

这篇关于如何从Java中的.ini文件读取子组值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆