For Python programmers the simlest API to use is ConfigParser. This sample presents accessing .ini files as Python ConfigParser objects.
This sample program expect the .ini file as a command line argument. If there is no such argument, it use the dwarfs-py.ini file.
import org.ini4j.ConfigParser; public class PyReadSample { public static final String FILENAME = "dwarfs-py.ini"; public static void main(String[] args) throws Exception { String filename = (args.length > 0) ? args[0] : FILENAME; ConfigParser config = new ConfigParser(); config.read(filename); for (String key : config.options("sleepy")) { System.out.println("sleepy/" + key + " = " + config.get("sleepy", key)); } } }
Standard output:
sleepy/name = sleepy sleepy/weight = 76.11 sleepy/height = 87.78 sleepy/age = 121 sleepy/homepage = http://snowwhite.tale/~sleepy sleepy/homedir = /home/sleepy