Java - 读取系统属性(System Properties)

文章目录

示例

代码:

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

参考

System Properties

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值