Thursday, May 28, 2015

Print current JVM's Java System Property

It print out all System Properties on console.
package com.devtrigger;

public class SystemProperty {

    public static void main(String... args) {

        System.getProperties().list(System.out);
    }
}


Then you pick up one property which you need and use it.
package com.devtrigger;

public class SystemProperty {

    public static void main(String... args) {

        System.out.println(System.getProperty("user.home"));
        System.out.println(System.getProperty("file.separator"));

...

        // create file object which is under user's home directory
        File file = new File (System.getProperty("user.home") + System.getProperty("file.separator") + "setting.xml");
    }
}


Referred from : System Properties

No comments:

Post a Comment