Guest User

Untitled

a guest
Sep 15th, 2018
119
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.23 KB | None | 0 0
  1. Overwritting properties files
  2. dbpassword=password
  3. database=localhost
  4. dbuser=user1
  5.  
  6. dbpassword=password
  7. database=localhost
  8. dbuser=user2
  9.  
  10. prop.setProperty("dbuser", "user2");
  11.  
  12. prop.store(new FileOutputStream("app.properties",true), null);
  13.  
  14. prop.store(new FileOutputStream("app.properties",false), null);
  15.  
  16. The example, PropertiesTest, creates a Properties object and initializes it from myProperties.txt .
  17.  
  18. subliminal.message = Buy StayPuft Marshmallows!
  19. PropertiesTest then uses System.setProperties to install the new Properties objects as the current set of system properties.
  20.  
  21.  
  22. import java.io.FileInputStream;
  23. import java.util.Properties;
  24.  
  25. public class PropertiesTest {
  26. public static void main(String[] args)
  27. throws Exception {
  28.  
  29. // set up new properties object
  30. // from file "myProperties.txt"
  31.  
  32. Properties p =
  33. new Properties(System.getProperties());
  34. p.load(propFile);
  35.  
  36. // set the system properties
  37. System.setProperties(p);
  38. // display new properties
  39. System.getProperties().list(System.out);
  40. }
  41. }
  42. Note how PropertiesTest creates the Properties object, p, which is used as the argument to setProperties:
  43.  
  44. Properties p = new Properties(System.getProperties());
Add Comment
Please, Sign In to add comment