Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Overwritting properties files
- dbpassword=password
- database=localhost
- dbuser=user1
- dbpassword=password
- database=localhost
- dbuser=user2
- prop.setProperty("dbuser", "user2");
- prop.store(new FileOutputStream("app.properties",true), null);
- prop.store(new FileOutputStream("app.properties",false), null);
- The example, PropertiesTest, creates a Properties object and initializes it from myProperties.txt .
- subliminal.message = Buy StayPuft Marshmallows!
- PropertiesTest then uses System.setProperties to install the new Properties objects as the current set of system properties.
- import java.io.FileInputStream;
- import java.util.Properties;
- public class PropertiesTest {
- public static void main(String[] args)
- throws Exception {
- // set up new properties object
- // from file "myProperties.txt"
- Properties p =
- new Properties(System.getProperties());
- p.load(propFile);
- // set the system properties
- System.setProperties(p);
- // display new properties
- System.getProperties().list(System.out);
- }
- }
- Note how PropertiesTest creates the Properties object, p, which is used as the argument to setProperties:
- Properties p = new Properties(System.getProperties());
Add Comment
Please, Sign In to add comment