集册 Java实例教程 读取环境变量

读取环境变量

欢马劈雪     最近更新时间:2020-01-02 10:19:05

486
提示:您可在线编辑运行本教程的实例 - 运行实例,去试试!
读取环境变量

public class Main { /**来自 N o w  J a v a  .   c o m**/

    public static void main(String[] args) { 

        if (args.length > 0) { 

            String value = System.getenv(args[0]); 

            if (value != null) { 

                System.out.println(args[0].toUpperCase() + " = " + value); 

            } else { 

                System.out.println("No such environment variable exists"); 

            } 

        } else { 

            System.out.println("No arguments passed"); 

        } 

    } 

}