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

查看:223
本文介绍了如何读取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

I认为使用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天全站免登陆