Home  >  Article  >  Java  >  Java basics to obtain system properties and environment variables

Java basics to obtain system properties and environment variables

高洛峰
高洛峰Original
2016-12-17 13:21:211434browse

As the title says, the code is relatively simple and is written for novices. Veterans can read other articles!

public static void main(String[] args) {  
        //属性  
        System.out.println("系统属性......");  
        Properties props = System.getProperties();  
        Set<Object> sets = props.keySet();  
        for (Object objKey : sets) {  
            System.out.println("属性名:【"+objKey+"】\n属性值:"+props.getProperty((String) objKey)+"\n");  
        }  
          
          
        //环境变量  
        System.out.println("\n\n环境变量......");  
        Map<String, String> env = System.getenv();  
        Set<String> keySet = env.keySet();  
        for (String key : keySet) {  
            System.out.println("【"+key+"】\t:\t【"+env.get(key)+"】\n");  
        }  
          
    }


For more articles related to Java basics of obtaining system properties and environment variables, please pay attention to the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn