如何在 Scala 中读取环境变量 [英] How to read environment variables in Scala

查看:28
本文介绍了如何在 Scala 中读取环境变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在 Java 中,读取环境变量是通过 System.getenv() 完成的.

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

有没有办法在 Scala 中做到这一点?

Is there a way to do this in Scala?

推荐答案

从 Scala 2.9 开始你可以使用 sys.env 来达到同样的效果:

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

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

我认为使用 Scala API 代替 Java 会很好.目前有几个项目可以将 Scala 编译到 JVM 以外的其他平台(.NET、javascript、native 等).减少对 Java API 的依赖,将使您的代码更具可移植性.

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.

这篇关于如何在 Scala 中读取环境变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆