This week's book giveaway is in the Java in General forum.
We're giving away four copies of Think Java: How to Think Like a Computer Scientist and have Allen B. Downey & Chris Mayfield on-line!
See this thread for details.
Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

System.properties or new properties object for reading a .properties file?

 
Gaurav Kr. Arora
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I am aware of two ways to read a .properties file:

1- System.getProperties.load(Inputstream for .properties file);

2- Creating a new Properties object and then calling load(Inputstream for .properties file);

In first approach, are we going to store values of .properties file in the System object. Is it utilizing more resources?

Would like to know which is the best way to do it or apart from above two ways, if there is any other best way, please let me know.

Thanks,
Vineet
 
Paul Clapham
Sheriff
Posts: 21107
32
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well, if you want access to the system properties, you would do the former. If you just want a class to contain a set of properties and you don't need the system properties, you would do the latter. The choice is nothing to do with performance, the choice is whether you need to read the system properties or not.

And the difference between the two is likely to be trivial anyway.
 
Gaurav Kr. Arora
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks a lot for the reply and clearing out the doubt! Is the System class of java has anything to do with my host machine?
 
Sai Hegde
security forum advocate
Ranch Hand
Posts: 212
1
Android Flex Google App Engine
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
System Properties will tell you about the operating system, the user, the version of Java.... of the host machine.
 
steve souza
Ranch Hand
Posts: 862
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Try loading the system properties and printing them (System.out.println(props)). Also there are other ways to load properties depending on what type of app you are running. For example xml files or for web apps the standard way you can load properties within web.xml etc. I like to abstract the way I am getting them from out of my code with an interface so I can change it without breaking my code.

As another poster stated there are no performance issues with any of the approaches.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic