我的Java代码如何读取OS环境变量? [重复]

时间:2022-05-01 11:46:22

This question already has an answer here:

这个问题在这里已有答案:

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)

#1


Try System.getenv(String name)

试试System.getenv(String name)