Home > Java > javaTutorial > body text

Java basics to obtain system properties and environment variables

高洛峰
Release: 2016-12-17 13:21:21
Original
1459 people have browsed it

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");  
        }  
          
    }
Copy after login


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

source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template