I have an ini file with ||
as the key value separator. I want to parse it using ini4j library but it is giving me an error (exception) whenever I run the code. I think that ini4j identifies only =
and :
as key-value separators. Is there any other way I could parse the file while using ini4j?
this is my example file
[header]
one||1
two||2
[section1]
three||3
four||4
five||5
six||6
[section2]
seven||7
eight||8
nine||9
this is my example code
public static void main(String[] args) throws IOException {
Ini ini=new Ini(new File("/home/esunmes/NetBeansProjects/ini4jexample/src/ini4jexample/newfile2.ini"));
for(String str:ini.keySet())
{System.out.println(str);
Ini.Section section=ini.get(str);
for(String key:section.keySet())
{System.out.println("the key is : "+key);// TODO code application logic here
}
}
I also want to know the case :key||value1||value2
How about replacing your delimeter with the expected =
?
String inputPropties = "KEY1||VALUE1\nKEY2||VALUE2\nKEY3||VALUE3";
inputPropties = inputPropties.replaceAll("\\|\\|","=");
Properties properties = new Properties();
properties.load(new StringReader(inputPropties));
for( String key: properties.stringPropertyNames()) {
System.out.println(key+" = "+properties.getProperty(key));
}