Accessing system properties can be an important part of the code/ J2EE application . Some of the system properties and their corresponding description are given below .
| Java system property | Meaning |
| file.encoding | The encoding used in text files on the system. |
| file.separator | The file separator character. This is usually \ for windows and / for UNIX like systems |
| java.io.tmpdir | The directory in which temporary files can be created on the local system. System environment variable %TEMP% |
| line.separator | The character or sequence of characters that generally mark a "new line" in a text file on the local operating system. On UNIX-like systems, this is typically a single ASCII character 10, whereas on Windows systems, this is typically a two-character sequence (ASCII 10 and ASCII 13). |
| os.name | The name of the local operating system, such as "Linux" or "Windows 7". |
| os.version | A version number of the local operating system, such as "6.0" or "2.6.18-stab02". |
| path.separator | The separator generally used to separate lists of paths on that operating system, for example a colon (":"). Note that this is not the directory separator used inside paths. |
| user.country | The ISO code of the operating system's (or local user's) configured country. |
| user.dir | The local directory from which the Java process has been started, and from which files will be read/written by default unless a path is specified. |
| user.home | The current user's "home" directory, such as C:\Users\Fred on Windows systems, or /home/sandesh/ on UNIX-like systems. |
| user.language | The ISO code of the operating system's (or local user's) configured language, such as "en" for English. |
| user.name | The local user's system user name. On Windows systems, this is typically close to a "real life" name. On UNIX-like systems, it is common for user names to be all lower case letters. |
import java.util.Map;
public class ReadSystemProperties {
public static void main(String[] args) {
Map envVars = System.getenv(); // Gives the environment variable values.
System.out.println(envVars);
String osVersion = System.getProperty("os.version"); // Retrives the version of os you are working on.
System.out.println("OS Version - \t" + osVersion);
String osName = System.getProperty("os.name"); // Retrives the os you are working on.
System.out.println("OS Version - \t" + osName);
String fileEncoding = System.getProperty("file.encoding"); // Retrives the os you are working on.
System.out.println("File Encoding - \t" + fileEncoding);
String fileSeparator = System.getProperty("file.separator"); // Retrives the os you are working on.
System.out.println("File Separator - \t" + fileSeparator);
}
}