Samples

The simple (but useful) samples you can find here illustrate the usage of [ini4j]. These are small, independent programs that may be translates and run. The build process of [ini4j] guarantees translatability and runability, since no distribution may be created without translating and running these programs. That's why these sources are not inserted into the document but can be found in separate .java files. But don't worry - your browser has a Back button, don't be afraid to use it :-)

The sample programs expect the .ini file as a command line argument. If there is no such argument, they use the dwarfs.ini file.

Using Java Preferences API

The samples below use the standard JDK Preferences API, so there's no need for any special [ini4j] API knowledge to understand them.

  • ReadStringSample.java
    This sample presents accessing String type values.
  • ReadPrimitiveSample.java
    Reading some Java primitive type values.
  • StreamSample.java
    This sample demonstrates that the Preferences API may be used without a filesystem access. In this case, naturally, there's no way of saving the altered settings, they may only be accessed in the memory.
  • ListenerSample.java
    This advanced sample presents the event-controlled usage. The [ini4j] library fully supports the events defined in Preferences API.
  • NoImportSample.java
    Using [ini4j] without class level dependency (no Java imports). You may use [ini4j] library as full Preferences implementation for user and system root.

Using [ini4j] API

The [ini4j] library has a simple API: the .ini file is a map of sections, while the section is a map of options. Due to the Java 1.5 generics these are type safe maps.

Using your own API !

Yes, it can be done! To access the contents of sections you can use any of your self-defined Java Beans compatible API. In order to do this you have to create a Java Beans-style interface, and a wrapper object that executes it will be generated by the [ini4j] library around the section.