Get/set system property
static String clearProperty(String key)
- Removes the system property.
static String getenv(String name)
- Gets the value of the specified environment variable.
static Properties getProperties()
- Determines the current system properties.
static String getProperty(String key)
- Gets the system property.
static String getProperty(String key, String def)
- Gets the system property.
static void setProperties(Properties props)
- Sets the system properties to the Properties argument.
static String setProperty(String key, String value)
- Sets the system property.
The following properties are available:
- file.separator
- java.class.path
- java.class.version
- java.compiler
- java.ext.dirs
- java.home
- java.io.tmpdir
- java.library.path
- java.specification.name
- java.specification.vendor
- java.specification.version
- java.vendor
- java.vendor.url
- java.version
- java.vm.name
- java.vm.specification.name
- java.vm.specification.vendor
- java.vm.specification.version
- java.vm.vendor
- java.vm.version
- line.separator
- os.arch
- os.name
- os.version
- path.separator
- user.dir
- user.home
- user.name
public class Main {
public static void main(String args[]) {
System.setProperty("myKey", "myValue");
System.out.println(System.getProperty("myKey"));
}
}
The output:
myValue
Determine operating system using System class
public class Main {
public static void main(String[] args) {
String strOSName = System.getProperty("os.name");
if (strOSName != null) {
if (strOSName.toLowerCase().indexOf("windows") != -1)
System.out.println("Windows");
else
System.out.print("not windows");
}
}
}
Windows
Home
Java Book
Essential Classes
Java Book
Essential Classes
System:
- System class
- Standard Stream
- Copy array
- Get/set system property
- Get the system environment
- Current system time