示例
代码:
public class Main {
public static void main(String[] args) {
String javaHome = System.getProperty("java.home");
String javaVendor = System.getProperty("java.vendor");
String javaVendorUrl = System.getProperty("java.vendor.url");
String javaVersion = System.getProperty("java.version");
String osArch = System.getProperty("os.arch");
String osName = System.getProperty("os.name");
String osVersion = System.getProperty("os.version");
String userDir = System.getProperty("user.dir");
String userHome = System.getProperty("user.home");
String userName = System.getProperty("user.name");
System.out.println("Installation directory for Java Runtime Environment (JRE): " + javaHome);
System.out.println("JRE vendor name: " + javaVendor);
System.out.println("JRE vendor URL: " + javaVendorUrl);
System.out.println("JRE version number: " + javaVersion);
System.out.println("Operating system architecture: " + osArch);
System.out.println("Operating system name: " + osName);
System.out.println("Operating system version: " + osVersion);
System.out.println("User working directory: " + userDir);
System.out.println("User home directory: " + userHome);
System.out.println("User account name: " + userName);
}
}
输出:
Installation directory for Java Runtime Environment (JRE): D:\F\Eclipse\eclipse\plugins\org.eclipse.justj.openjdk.hotspot.jre.full.win32.x86_64_16.0.2.v20210721-1149\jre
JRE vendor name: Oracle Corporation
JRE vendor URL: https://java.oracle.com/
JRE version number: 16.0.2
Operating system architecture: amd64
Operating system name: Windows 10
Operating system version: 10.0
User working directory: D:\F\eclipse-workspace\test
User home directory: C:\Users\Admin
User account name: Admin