Writing the .ini file received as input to the stand output.
This sample program expect the .ini file as a command line argument. If there is no such argument, it use the dwarfs.ini file.
import org.ini4j.Ini; import java.io.FileReader; public class DumpSample { public static final String FILENAME = "dwarfs.ini"; public static void main(String[] args) throws Exception { String filename = (args.length > 0) ? args[0] : FILENAME; Ini ini = new Ini(new FileReader(filename)); for (Ini.Section section : ini.values()) { System.out.println("[" + section.getName() + "]"); for (String option : section.keySet()) { System.out.println(option + " = " + section.fetch(option)); } System.out.println(); } } }
Standard output:
[bashful] weight = 45.7 height = 98.8 age = 67 homePage = http://snowwhite.tale/~bashful homeDir = /home/bashful [doc] weight = 49.5 height = 87.7 age = 63 homePage = http://doc.dwarfs homeDir = c:Documents and Settingsdoc [dopey] weight = 45.7 height = 87.7 age = 23 homePage = http://dopey.snowwhite.tale/ homeDir = c:\Documents and Settings\dopey fortuneNumber = 55 [grumpy] weight = 65.3 height = 87.7 age = 76 homePage = http://snowwhite.tale/~grumpy/ homeDir = /home/grumpy [happy] weight = 56.4 height = 77.66 age = 99 homePage = http://happy.smurf homeDir = /home/happy [sleepy] weight = 76.11 height = 87.78 age = 121 homePage = http://snowwhite.tale/~sleepy homeDir = /home/sleepy fortuneNumber = 99 [sneezy] weight = 69.7 height = 76.88 age = 64 homePage = http://happy.smurf/~sneezy homeDir = /home/sneezy fortuneNumber = 44