Map.Keyset () method does not return all keys

3

Friends, I have a problem and I can not identify the cause.

I have a properties file here . I'm reading it normally but when I'm going to get all its keys by Map.keySet() method not all keys are being returned.

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

// load a properties file
prop.load(input);
for (Object string : prop.keySet()) {
   System.out.println(string.toString());
}

The output is not corresponding to all the keys in the file.

I performed another test reading all the lines of the file with FileReader and I used a regular expression to separate [ key , value ].

I noticed that the reading was done correctly, and afterwards, I assigned each key and value pair to a Map<String, String> and realized that the following lines are not being assigned to the map keys:

ArquivoSefipVisao.cabecalho.dataRecolhimentoPrevidenciaSocial
ArquivoSefipVisao.$COLECAO.listaCabecalhoEmpresa.informacaoAdicional.tipoInscricaoEmpresa
ArquivoSefipVisao.$COLECAO.listaCabecalhoEmpresa.informacaoAdicional.inscricaoEmpresa
ArquivoSefipVisao.$COLECAO.listaCabecalhoEmpresa.informacaoAdicional.receitaEventoDesportivoPatrocinio
ArquivoSefipVisao.$COLECAO.listaCabecalhoEmpresa.informacaoAdicional.indicativoOrigemReceita
ArquivoSefipVisao.$COLECAO.listaCabecalhoEmpresa.informacaoAdicional.recolhimentoDeCompetenciasAnterioresInss
ArquivoSefipVisao.$COLECAO.listaCabecalhoEmpresa.informacaoAdicional.recolhimentoDeCompetenciasAnterioresOutrasEntidades
    
asked by anonymous 11.03.2015 / 19:27

2 answers

0

Gelera, I solved the problem by implementing my own properties reader using regular expression and a linked list to maintain order. I was unable to use the properties, the above problem was occurring.

    
12.06.2015 / 19:55
0

Hello, try this:

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

try {

    String filename = "config.properties";
    input = getClass().getClassLoader().getResourceAsStream(filename);
    if (input == null) {
        System.out.println("Sorry, unable to find " + filename);
        return;
    }

    prop.load(input);

    Enumeration<?> e = prop.propertyNames();
    while (e.hasMoreElements()) {
        String key = (String) e.nextElement();
        String value = prop.getProperty(key);
        System.out.println("Key : " + key + ", Value : " + value);
    }

} catch (IOException ex) {
    ex.printStackTrace();
} finally {
    if (input != null) {
        try {
            input.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
    
11.03.2015 / 19:39