Pradeep's Blog

Google

Monday, April 03, 2006

System properties in Java

Want to find out the system's default temp directory, users home directory, user’s name, the path, file or the line separator. These things become very useful if you consider to your application to be platform independent. Finding out these things in java has always been easy.
The System class maintains a set of properties, key/value pairs, which define properties of the current working environment. When the JRE first start these system properties are initialised to contain information about the runtime environment. The complete list of system properties can be found here:

Reading System Properties:

The System class has two methods that you can use to read the system properties: getProperty and getProperties. The example below shows how you can print the user’s home directory.

String home = System.getProperty("java.home");
System.out.println(home);

Writing System Properties:

Though java allows us to overwrite the system properties, it should be done with caution. Any how here’s how it can be done.

java.home =”c:\temp “;

This would make change the user’s home directory to the path specifies in the string.
References:

0 Comments:

Post a Comment

<< Home