This question already has an answer here:
这个问题在这里已有答案:
- Can we read the OS environment variables in Java? 2 answers
我们可以在Java中读取OS环境变量吗? 2个答案
This may be a very simple problem, but I couldn't find an answer googleing and I'm in a rush - so I'd appreciate fast code examples.
这可能是一个非常简单的问题,但我找不到答案googleing而且我很匆忙 - 所以我很欣赏快速的代码示例。
I have an environment variable on the OS I would like to read using Java code. I've tried System.getProperty
, but that only seems to work for the -D
variables supplied directly for the JVM.
我想在OS上使用Java代码阅读的OS上有一个环境变量。我已经尝试过System.getProperty,但这似乎只适用于直接为JVM提供的-D变量。
How can my Java code read OS variables?
我的Java代码如何读取OS变量?
1 个解决方案
#1
Try System.getenv(String name)
试试System.getenv(String name)