how to pick up a list of properties

0

Good morning to everyone,

I need to collect data from a list that I have in a .properties.

example: numbers = 124234,12342343,12234234,234234,234234,23423

and collect it in java to be able to compare it with the number that has been asked to the user to know if he is awarded. Been searching and can not find the way to create the list (if it should be collected as in the example or in another way) and how to recover it in java list. Recover values of properties in java but for more than try I can not recover a list of values.

Greetings and thanks for your time.

    
asked by kiristof 18.01.2018 в 11:31
source

2 answers

1

Good!

To do it as you have thought, by entering the list of values in a single variable of the properties, you can do so:

Properties prop = new Properties();
InputStream input = null;

try {

    input = new FileInputStream("config.properties");

    // load a properties file
    prop.load(input);

    String valor = prop.getProperty("numeros");
    String[] valores = valor.split(",");

} catch (IOException ex) {
    ex.printStackTrace();
} finally {
    if (input != null) {
        try {
            input.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}

and if you want it in a list, as the comrade says:

List<String> lista = Arrays.asList(valores);

Greetings

    
answered by 18.01.2018 / 14:45
source
0

The easiest thing is that you do

ResourceBundle bundle = ResourceBundle.getBundle("NombreFichero");
String[] valores = bundle.getStringArray("numeros");

If what you want is a List<String> and not an Array:

List<String> lista = Arrays.asList(valores);
    
answered by 18.01.2018 в 11:48