在使用Java进行开发的时候,常常需要用到系统的一些属性,可以通过调用java.lang.system类中的getProperties()方法或getProperty(String key)方法来获取当前系统的属性。
1java.util.Properties currentProperties =
System.getProperties();//获取当前系统所有的属性
2currentProperties.list(System.out);//在屏幕上输出
2currentProperties.list(System.out);//在屏幕上输出
// 通过指定属性名,获取相应的系统属性
1String osName = System.getProperty("os.name" );
2String osVersion = System.getProperty("os.version" );
3String osArch = System.getProperty("os.arch" );
4String userName = System.getProperty("user.name" );
5String userHome = System.getProperty("user.home" );
6String userDir = System.getProperty("user.dir" );
7String userTimezone = System.getProperty("user.timezone" );
8String javaHome = System.getProperty("java.home" );
9String javaVersion = System.getProperty("java.version" );
10String javaClassPath = System.getProperty("java.class.path" );
11String javaClassVersion = System.getProperty("java.class.version" );
12String javaVendor = System.getProperty("java.vendor" );
13String javaVendorURL = System.getProperty("java.vendor.url" );
14String pathSeparator = System.getProperty("path.separator" );
15String lineSeparator = System.getProperty("line.separator" );
16String fileSeparator = System.getProperty("file.separator" );
17String fileEncoding = System.getProperty("file.encoding");
1String osName = System.getProperty("os.name" );
2String osVersion = System.getProperty("os.version" );
3String osArch = System.getProperty("os.arch" );
4String userName = System.getProperty("user.name" );
5String userHome = System.getProperty("user.home" );
6String userDir = System.getProperty("user.dir" );
7String userTimezone = System.getProperty("user.timezone" );
8String javaHome = System.getProperty("java.home" );
9String javaVersion = System.getProperty("java.version" );
10String javaClassPath = System.getProperty("java.class.path" );
11String javaClassVersion = System.getProperty("java.class.version" );
12String javaVendor = System.getProperty("java.vendor" );
13String javaVendorURL = System.getProperty("java.vendor.url" );
14String pathSeparator = System.getProperty("path.separator" );
15String lineSeparator = System.getProperty("line.separator" );
16String fileSeparator = System.getProperty("file.separator" );
17String fileEncoding = System.getProperty("file.encoding");