• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • Ron McLeod
  • Junilu Lacar
  • Liutauras Vilda
Sheriffs:
  • Paul Clapham
  • Jeanne Boyarsky
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Piet Souris
  • Carey Brown
Bartenders:
  • Jesse Duncan
  • Frits Walraven
  • Mikalai Zaikin

Property

 
Ranch Hand
Posts: 182
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Could I have an example of how to use java.util.Property
Is it the same used for storing an environment variable.

My Queries:
1) Say i had stored my key-value values in Project.properties file
Now in my code how do i read the values from the Project.properties files

2) Can i add some values dynamically from code to the Project.properties

3) Could I get the values of Project.properties from System.getProperty() or could i load the project.proerties from System.getProperty()

Thanks,
aakash
 
Author and all-around good cowpoke
Posts: 13078
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If you will look at the JavaDocs for java.util.Properties, you will see that it has the load( InputStream ), store( OutputStream ) and setProperty( key, value) methods. These take care of 1) and 2)
You should not be trying to use the System properties for your specific application. Use a separate properties file.
Bill
 
Ranch Hand
Posts: 1970
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by aakash bhatt:
Is it the same used for storing an environment variable.


As far as I know, Java does not support OS environment variables, except via a deprecated method on java.lang.System. It has been deprecated since an early version and may not do anything at all now. Certainly, you should not use it.

You can use platform-specific code to get/set OS environment variables, with JNI.

Anyone know why OS environment variables are unsupported by Java? What platform didn't like them? The concept exists in all DOS/Windows/Unix/Linux/MacOSX.
 
pie. tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic