Accessing the whole .ini file as Java Beans-style beans.

This sample program expect the .ini file as a command line argument. If there is no such argument, it use the dwarfs.ini file.

Source code for beans: Dwarf, Dwarfs

import org.ini4j.Ini;


public class BeanSample
    public static final String FILENAME = "dwarfs.ini";

    public static void main(String[] args) throws Exception
        String filename = (args.length > 0) ? args[0] : FILENAME;
        Dwarfs dwarfs = new Ini(new FileInputStream(filename)).as(Dwarfs.class);
        Dwarf happy = dwarfs.getHappy();
        Dwarf doc = dwarfs.getDoc();

        System.out.println("Happy's age: " + happy.getAge());
        System.out.println("Doc's age: " + doc.getAge());

Standard output:

Happy's age: 99
Doc's age: 44