6

Here is a sample ini file:

[link#1]
alias=My Link 1
link=https://www.yandex.ru/

[link#2]
alias=My Link 2
link=https://mail.ru/

[link#3]
alias=My Link 3
link=http://point.md/ru/

I've seen how to parse it, but the keys are the same, and I need to get this into lets say ArrayList<LinkObject> . Does anyone know a good solution for this? Or shall we format the .ini file differently?

Tomasz Jakub Rup
  • 10,502
  • 7
  • 48
  • 49
Filip Luchianenco
  • 6,912
  • 9
  • 41
  • 63

1 Answers1

8

I can suggest you ini4j. This is small and very easy to use library. Just download files or include dependency into your maven config:

<dependency>
   <groupId>org.ini4j</groupId>
   <artifactId>ini4j</artifactId>
   <version>0.5.4</version>
</dependency>

Now to load .ini file just do:

Wini ini = new Wini(new File("your file path"));

Examples of usage:

//output names of all sections    
Collection<Profile.Section> list = ini.values();
for(Profile.Section section : list){
    System.out.println(section.getName());
}

//fetch and output option value
String value = ini.fetch("link#1", "alias");
System.out.println(value);

//output keys of all options of one section
Profile.Section section = ini.get("link#1");
for(String key : section.keySet()){
   System.out.println(key);
}
Ken Bekov
  • 13,696
  • 3
  • 36
  • 44
  • Thank you for detailed explanation. – Filip Luchianenco Jan 06 '16 at 18:33
  • 1
    Thank you for your Examples. I tried half an hour to read out an xml. And I still don't have a clue what todo with a Node object. But thanks to you I understand it right away –  Feb 04 '19 at 15:20