0

I have a configuration file formatted as this,

object1=1
object2=2
object3=3
array={ 
   sub_object1=sub_1
   sub_object2=sub_2
   sub_object3=sub_3
}
object4=4
object5=5

I have been trying to process this with Properties.getProperty, but am unable to find an effective method to process the array.

    try {

        Properties props = new Properties();

        props.load( new FileInputStream( "settings.conf" ) );

        if( !props.isEmpty() ) 
        {
            props.stringPropertyNames().stream().forEach((key) -> 
            {
                if( !key.equals( "array" ) ) 
                {
                    List<Object> subkeys = props.list();

                    for( subkeys: subkey  ) )
                    {
                        System.out.println( "Subkey: " + props.getProperty( subkey ) );
                    }
                }
            });
        }
    } catch ( Exception e ) {
        e.printStackTrace();
    }

I realize the above is errorous, but I have been unable to find a solution. Any one have an idea?

woahguy
  • 261
  • 3
  • 13
  • This file doesn't respect the properties file format. You shouldn't use Properties to parse it. Write your own parser, or use a standard format that can be easily parsed, and supports tree structures, like JSON. – JB Nizet Jan 25 '16 at 22:49
  • You may check this [post](http://stackoverflow.com/questions/7015491/better-way-to-represent-array-in-java-properties-file). Hope this helps. – jmj Jan 25 '16 at 22:49
  • You can't do this by your way. And Properties hasn't array support from box. But you can define your property with comma separated list, then read it and split to array. – eg04lt3r Jan 25 '16 at 22:49
  • It's OK you need to include an array into your configuration file, but I don't understand why it contains pairs of keys-values, since an array is supposed to contain just values. In your example, what the `List subkeys` is supposed to contain? – Little Santi Jan 25 '16 at 23:21

0 Answers0