Question:
How to set a system property using a property file?
Code:
import java.io.FileInputStream; import java.util.Properties; public class PropertiesTest { public static void main(String[] args) throws Exception { // set up new properties object FileInputStream propFile = new FileInputStream( "myProperties.txt"); Properties p = new Properties(); p.load(propFile); // set the java properties System.setProperties(p); // display the properties System.getProperties().list(System.out); } }
Output:
$ cat myProperties.txt mprop=some prop some.number=12345 com.foo.bla=abcdefg1234567 $ java PropertiesTest -- listing properties -- some.number=12345 com.foo.bla=abcdefg1234567 mprop=some prop