-2

我有一个带有||键值分隔符的 ini 文件。我想使用 ini4j 库解析它,但每当我运行代码时它都会给我一个错误(异常)。我认为 ini4j 仅标识=:作为键值分隔符。在使用ini4j时有没有其他方法可以解析文件?

这是我的示例文件

[header]
one||1
two||2

[section1] 
three||3
four||4
five||5
six||6

[section2]
seven||7
eight||8
nine||9

这是我的示例代码

 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
}

}

我也想知道案例:key||value1||value2

4

1 回答 1

1

用预期的分隔符替换你的分隔符怎么样=

    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));
    }
于 2013-06-10T08:20:23.173 回答