How to read environment variables in Scala

前端 未结 6 612
渐次进展
渐次进展 2020-12-12 13:23

In Java, reading environment variables is done with System.getenv().

Is there a way to do this in Scala?

6条回答
  •  一整个雨季
    2020-12-12 14:15

    Using directly a default with getOrElse over the sys.env Map (val myenv: Map[String, String] = sys.env):

    sys.env.getOrElse(envVariable, defaultValue)
    

    You get the content of the envVariable or, if it does not exist, the defaultValue.

提交回复
热议问题