Home Java Java-get-example Java get set Properties



Java get set Properties
Posted on: November 1, 2008 at 12:00 AM
In this section, you will learn how to modify the set of system properties by adding a new property.

Java get set Properties

     

In this section, you will learn how to modify the set of system properties by adding a new property. In the example given below, we have create a new property listed in the 'NewProperties.txt' file i.e java.company=Roseindia Pvt Ltd which is not an actual System Property

Properties prop = new Properties(System.getProperties())- This statement initializes the new properties object, prop with the current set of system properties. 

prop.load(propFile) - This method loads the additional property into prop from the file NewProperties.txt.

System.setProperties(prop)- This method takes the Properties object and add the property into the current system properties. It will change the set of system properties for the current running application.

Here is the code of GetSetProperties.java

import java.io.FileInputStream;
import java.util.Properties;

public class GetSetProperties {
  public static void main(String[] args) throws Exception {
  FileInputStream propFile = new FileInputStream(
   "NewProperties.txt");
  Properties prop = new Properties(System.getProperties());
  prop.load(propFile);
  System.setProperties(prop);
  System.getProperties().list(System.out);
  }
}

On the console, you can see a newly added property:

Download Source Code

Related Tags for Java get set Properties:
javaccomfilelistpropertiesiopropertysystemnewthissetcreateiftxtieexampleaddcompanytolearnexammodifyeareilsectionnotlipeinnomodaddinaddingmosddosjadestdemhowmodipropansystiexawhichxampsatanyishallivmplproperdiaeaactualaractrtropextvassthavbelost.compleplpropprndonomo


More Tutorials from this section

Ask Questions?    Discuss: Java get set Properties  

Post your Comment


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 

Ask Questions?

If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.

Ask your questions, our development team will try to give answers to your questions.