-1

I am trying to retrieve the group of values from property file based on the key.

myproerty.properties

key=1
name=adam
place=USA
address=Michigan

Key=2
name=umesh
place=india
address=bengaluru

I want to retrieve values of that particular key values.

Earlier i tried using the below method but it doesnt differentiate key.

myProperties = new Properties();
myProperties.load(HelloWorld.class.getResourceAsStream("/myproerty.properties")); 
name=myProperties.getProperty("adam");

but how do we retrieve group of values based on the key

  • You're not passinf a key but a value. Also this is unclear what your problem is – azro May 28 '20 at 08:33
  • if i am passing 1, i should be able to get name=adam place=USA address=Michigan – tulu matinee May 28 '20 at 08:35
  • This is not possible with the standard `Properties` class in the JDK. – Seelenvirtuose May 28 '20 at 08:36
  • That is not the way it works. This is a list of key/value separated with a '=', pass `key` get 1, pass `name` get adam – azro May 28 '20 at 08:36
  • This is not how properties file works in Java. For your requirement use a database table instead and fetch all properties using a primary key. – Som May 28 '20 at 08:39
  • 1
    Don’t tag a question with every Java version that comes into your mind. What kind of statement is this supposed to make? – Holger May 28 '20 at 10:59

1 Answers1

-1

It seems that you need to read your properties file as INI file. Take a look:

  1. How to parse ini file with sections in Java?
  2. What is the easiest way to parse an INI file in Java?

So, your file should look like that:

[key1]
name=adam
place=USA
address=Michigan

[Key2]
name=umesh
place=india
address=bengaluru

and use a library like ini4j for parsing such ini files.

Getodac
  • 79
  • 6