Srikar Srikar - 1 year ago 98
Ini Question

Ini file parsing in java

I'm trying to read INI file using ini4j. The format is

key = value

Ini confFile = new Ini(new File(filePath));
Map<String, String> technologyMap = confFile.get("header");

for (Map.Entry<String, String> techMap : technologyMap.entrySet()) {
System.out.println(confFile.get("header", "\"" + techMap.getKey() + "\"");

I'm getting
as my output.

If I pass the value statically I'm getting my proper output, i.e.

System.out.println(confFile.get("header", "value");

is giving the expected output.

What is the problem here to pass values dynamically?

Answer Source

Of course you get null. There is no option in section header named "key" (notice the quotes you added).

If you just want to dump all the values in a section (though why you'd want to dump values without their keys is beyond me), do this:

for (String value : technologyMap.values()) {

If you actually want to print the keys too (makes more sense), so this:

for (Map.Entry<String, String> entry : technologyMap.entrySet()) {
    System.out.println(entry.getKey() + ": " + entry.getValue());

Calling confFile.get("header", key), when you already have the value, is not the right way to go.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download