Save multi-value key in Properties file

3

I have a .properties file where I load the name of the tests that will be deleted from my application. This file needs to have the same name as the "variables" since they all mean the same thing (excluded tests), the problem is that my code is only recognizing the last test (the NATONE in case).

data.properties:

prop.teste.excl = CQT-SUST
prop.teste.excl = NATONE

code:

public static Properties getProp() throws IOException 
{
    Properties props = new Properties();
    FileInputStream file = new FileInputStream("src/resources/dados.properties");
    props.load(file);
    return props;

}

public ArrayList<String> testeInterno() throws IOException 
{
    String property;
    ArrayList<String> testeInt = new ArrayList<String>();

    Properties prop = getProp();

        for ( int i = 0; i < prop.size(); i++)
        {
            property = "prop.teste.excl"; 
            testeInt.add(i, prop.getProperty(property));

            System.out.println(testeInt.get(i));
        }

    return testeInt;
}

I thought about putting ";" at the end of each line of my file but I do not know how to do the code that recognizes the ";" as end of line and also do not know if it would work.

    
asked by anonymous 13.11.2017 / 17:04

1 answer

3

You can insert them in the same property key separating by comma, and then you treat the return as String , separating the values with the split method, passing the comma as a separator:

Example:

prop.teste.excl = CQT-SUST,NATONE

And when it comes to dealing with:

String[] array = prop.getProperty("prop.teste.excl").split(",");

In this way, you will have an array with the values of the key "prop.teste.excl" , which were separated by commas.

    
13.11.2017 / 17:16