• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Accessing the Properties File

 
Senthil Kumar
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,
Iam trying to acces the Properties in my code.
But the Keys are accessed in the same order as it is in the Properties file.
Iam using the following code.

properties.load(new FileInputStream("C:\\SampleProperties2.properties"));
enumProperties = properties.propertyNames();
while(enumProperties.hasMoreElements()){
key = (String)enumProperties.nextElement();
System.out.println(key+"---->"+properties.getProperty(key));
}


Is there a way to access the Keys in the same way as it is defined in the Properties File?

Thanks in advance
Senthil Kumar.S
 
Ulf Dittmer
Rancher
Posts: 42967
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is there a way to access the Keys in the same way as it is defined in the Properties File?


Not through the Properties class. You'd have to read and parse the file in your own code. But properties are not meant to have an ordering; they constitute a map (or hash table). Why is that important - maybe there are other ways of achieving what you need done?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic