System Properties 系统环境变量

系统环境变量:

KeyMeaning
"file.separator" Character that separates components of a file path. This is "/" on UNIX and "\" on Windows.
"java.class.path" Path used to find directories and JAR archives containing class files. Elements of the class path are separated by a platform-specific character specified in the path.separator property.
"java.home" Installation directory for Java Runtime Environment (JRE)
"java.vendor" JRE vendor name
"java.vendor.url" JRE vendor URL
"java.version" JRE version number
"line.separator" Sequence used by operating system to separate lines in text files
"os.arch" Operating system architecture
"os.name" Operating system name
"os.version" Operating system version
"path.separator" Path separator character used in java.class.path
"user.dir" User working directory
"user.home" User home directory
"user.name" User account name

 

代码举例:

        // 获取当前的工作目录
        String userDir = System.getProperty("user.dir");
        log.info("userDir:[{}]" + userDir);
//        信息: userDir:[{}]E:\workspace\XXX
        
        // 获取所有系统变量
        Properties properties = System.getProperties();
        log.info("properties:【{}】" + properties.toString());

 

参考文档:

https://docs.oracle.com/javase/tutorial/essential/environment/sysprop.html

posted @ 2021-01-11 15:34  星瑞  阅读(249)  评论(0编辑  收藏  举报