Map.Keyset() method does not return all keys

Asked

Viewed 251 times

3

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

I have a property file here. I’m reading it normally but when will I get all his keys by the method Map.keySet() 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());
}

Output is not matching all file keys.

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

I realized that the reading was performed correctly, and soon after, I assigned each key and value pair in a Map<String, String> and I realized that the following lines are not being assigned in 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
  • tried the way I posted below?

2 answers

0


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

0

Hello, try this way:

    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();
        }
    }
}
  • It didn’t work, my problem is the properties that somehow doesn’t store all my keys in keyset. But I solved the problem by implementing a "Propertiesutil by reading the line of the file and using regular expression"

  • 1

    Put the answer to help future questions.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.