How to read environment variables in Scala

前端 未结 6 618
渐次进展
渐次进展 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:01

    Since Scala 2.9 you can use sys.env for the same effect:

    scala> sys.env("HOME")
    res0: String = /home/paradigmatic
    

    I think is nice to use the Scala API instead of Java. There are currently several project to compile Scala to other platforms than JVM (.NET, javascript, native, etc.) Reducing the dependencies on Java API, will make your code more portable.

提交回复
热议问题