Questions tagged [ini4j]

The ini4j is a simple Java API for handling configuration files in Windows .ini format. Additionally, the library includes Java Preferences API implementation based on the .ini file.

The ini4j is a simple Java API for handling configuration files in Windows .ini format. Additionally, the library includes Java Preferences API implementation based on the .ini file.

Configuration management is an integral part of every application. The standard Java API Properties warrants simple configuration management. A bit more complicated configuration can be managed with the standard Java Preferences API since Java version 1.4. There is also another (much more complicated) method of configuration management: managing configuration files in XML format. In this case the standard Java XML API (JAXP) or another XML-based configuration management system, e.g. Jakarta Commons Digester, is used.

The Properties file can't group settings, which is why its services are often not sufficient. The Preferences API can sort settings in a nice tree structure, but the standard implementation uses hidden filesystem directory structures inside the user's home directory. This means that it can't be used for managing configuration files attached to the application. Managing XML configuration files through the JAXP is a tiresome work, and to learn and master a complex XML-based configuration management system is a time-consuming and difficult task.

There is another way not mentioned so far: using good old Windows .ini files. This format allows you to group settings, so it's better than the Properties API, whereas it's considerably easier to manage than XML configuration files. Contrary to the standard Preferences implementation, .ini files can be attached to applications as configuration files without worry. At the time of writing this document a "de facto" .ini file handling Java library doesn't exist. The ini4j tries to be one.

It was an important design aspect to use the standard API. Due to this, I chose the standard Preferences API. This means that the ini4j package contains a Preferences implementation that realizes a Preferences API on the .ini files. The Preferences tree has only one level that contains the sections of the .ini file. The only ini4j specific thing that remains is to create a Preferences tree that means creating an instance of the IniPreferences object. This object corresponds to the .ini file as a Preferences object.

The Properties file is a simple String,String map, while the Ini object is a two-level map. On its first level the String type keys define the Ini.Section type sections. The Ini.Section object itself is a map, a String,String type map of the name/value pairs.

Official Website: http://ini4j.sourceforge.net/

Useful Links:

53 questions
11
votes
4 answers

ini4j - How to get all the key names in a setting?

I've decided to use ini file to store simple key-value pair configuration for my Java application. I googled and searched stackoverflow and found that ini4j is highly recommended for parsing and interpreting ini files in Java. I spent some time…
codingbear
  • 14,773
  • 20
  • 48
  • 64
5
votes
2 answers

Reading path from ini file, backslash escape character disappearing?

I'm reading in an absolute pathname from an ini file and storing the pathname as a String value in my program. However, when I do this, the value that gets stored somehow seems to be losing the backslash so that the path just comes out one big…
user2521350
  • 85
  • 1
  • 9
4
votes
1 answer

ini4j store method changes the comment character

I want to change the entry of a key in a section of an ini file. I use the ini4j library. So I wrote the code below. I can change the entry but there are also other changes which I don't want: replacement of ";" with "#" which indicates comment…
Ceren Baş
  • 41
  • 3
3
votes
3 answers

Parsing error after '#' line in ini file

I have a locally stored ini file which I am trying to parse as follows: Ini ini = new Ini(new File("path/to/file")); System.out.println(ini.get("header", "key")); But I keep getting a parse error exception message pointing to the line after the…
Kylie Irwin
  • 195
  • 3
  • 11
3
votes
0 answers

Ini4J Changing my Entire INI file Instead of 1 Key Setting

I am writing a Java application that I just need it to make a change to one key setting within an ini file. I am using ini4j to do this, but have come across some issue when loading the file. The file looks like what I have here below: [SECTION…
alex-ayala
  • 73
  • 9
2
votes
1 answer

Ini4j - How to close the file stream after parsing error

I have the following code below which uses the ini4j library to load a file as a .ini file. Ini configIni; public void setupConfig() { String configFilePath = "config.ini"; File config = new File(configFilePath); …
Laeven
  • 23
  • 4
2
votes
1 answer

ini4j API - read all keys of section and create a map of it

I'm new to ini4j API http://mvnrepository.com/artifact/org.ini4j/ini4j. I have a requirement where if pass key as CT then it should check all section and populate key value pair in Java Map(like 10=CT,11=CT etc). How we can do this? Cities are not…
user5268786
2
votes
1 answer

ini4j character encoding

I'am using library ini4j for work with ini file's. My problem is, when i make a ini file: try (PrintWriter writer = new PrintWriter("path" + ".ini", "UTF-8")) { writer.println("[Main_Menu]"); writer.println("TEST = Příliš…
paetreph
  • 53
  • 1
  • 4
2
votes
3 answers

Read multiple values from an ini file, preserving order

I have the following Ini-File [Test] a=1 b=2 a=3 and I need these key value pairs in the correct order. My problem is, I can find no way to achieve this. I tried the following three options: Ini ini = new Ini(new File("test.ini")); for (String…
xani
  • 784
  • 1
  • 7
  • 21
1
vote
1 answer

In Java, deal with NoClassFoundError

My project is built using Apache Maven JAR Plugin, I'm using ini4j inside my project managed by maven, on the IDE, everythin works fine. But when i try to launch the JAR in the cmd as follow : java -jar javaProgram-1.0-SNAPSHOT.jar I get this error…
Khysra
  • 25
  • 4
1
vote
1 answer

ini4j store not working

Following the simple ini4j tutorial I wrote a class to read and write JDBC connections. Here is what I do when clicking on the dialog buttons: public void actionPerformed(ActionEvent ae){ JButton b = (JButton)ae.getSource(); if (b == save…
1
vote
2 answers

Using ini4j to edit Windows registry

Im currently working on a java program and I need to read/write to the registry. i've looked at several API's to do this and I found ini4j (ini4j Project Page). I also need to edit ini files so I like this solution because it does both. I'm…
GEverding
  • 3,131
  • 2
  • 21
  • 23
1
vote
2 answers

Ini4j not reading file paths

I have a .ini file that looks like this: [Filepath] Inbound=C:\Users\Bilbo\Desktop\Testing I want to return that exact string (C:\Users\Bilbo\Desktop\Testing) and I have the following code: public static String ParseIniInbound (File iniFile)…
Warrior990
  • 59
  • 1
  • 5
1
vote
3 answers

ini4j Is not finding existing key in .ini file

So i have this block of code that is supposed to check and make sure the required keys exist but nomatter if they exist or not it will always call the code in the if block else { Wini ini = new Wini(new File("config.ini")); …
craftxbox
  • 220
  • 1
  • 3
  • 12
1
vote
1 answer

ini4j Read File Error

I am trying to use ini4j. But I am not able to read the file. The code: ini = new Wini(new InputStreamReader(new FileInputStream("./setup.ini"), "UTF-8")); But it is giving me the errors: Unhandled exception type IOException Unhandled exception…
Niklas Riecken
  • 303
  • 1
  • 6
  • 20
1
2 3 4